Add --sigterm flag - #65
Merged
Merged
Conversation
# Conflicts: # src/slipcover/__main__.py
The handler called sci_atexit() manually and then sys.exit(0), which re-triggers the same already atexit.register()'d sci_atexit() a second time during normal interpreter shutdown -- removing the redundant manual call fixes this; atexit already runs it exactly once. A forked child inheriting the handler also went through this same top-level path instead of the already-shimmed os._exit() (which correctly writes the child's own coverage to a tempfile for the parent to merge), racing the real parent for the same --out file and silently dropping the child's coverage on merge. Adds --sigterm to config.py's _BOOL_KEYS (caught immediately by the drift-detecting oracle test), and two integration tests exercising the real --sigterm flag and real signal delivery end to end (no internal functions called directly): one confirms the report is written exactly once on a top-level SIGTERM, the other has the target script fork for real and SIGTERMs the child specifically, confirming its partial coverage survives the merge instead of being lost. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
|
CI has been stuck due to GitHub's Actions incident. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
--sigtermflag (matching coverage.py'ssigtermflag) to still write the coverage output if aSIGTERMsignal is sent.Helpful for using slipcover in e.g. docker containers.
Tested with a simple
while True: ...script and then akill -SIGTERM. I'm not too familiar with what sort of cleanup may be necessary for more complex cases, so I'd welcome any suggestions on how to truly gracefully exit.Also, this currently ignores
--fail-under, since it exits immediately instead. I'm happy to update it to e.g. raise an exception that is caught by a context manager surrounding therunpy/execcalls, so that the normal flow in__main__afterwards is maintained. I chose not to for now, since theatexitisn't currently doing that either.Thanks for creating/maintaining this project!
Update: fixed two bugs in the original handler: it called
sci_atexit()manually and thensys.exit(0), which re-triggered the same already-registeredatexithandler a second time, double-writing the report; and a forked child inheriting the handler went through that same top-level path instead of the already-shimmedos._exit(), racing the real parent for--outand silently dropping the child's coverage on merge. Added two integration tests exercising real--sigterm+ real signal delivery (including a real forked child) end to end. The--fail-undercaveat above is still accurate and unaddressed.