Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/slipcover/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import platform
import functools
import os
import signal
import tempfile
import json
import warnings
Expand Down Expand Up @@ -159,6 +160,7 @@ def main():
ap.add_argument('--threshold', type=int, default=50, metavar="T",
help="threshold for de-instrumentation (if not immediate)")
ap.add_argument('--missing-width', type=int, default=80, metavar="WIDTH", help="maximum width for `missing' column")
ap.add_argument('--sigterm', action='store_true', help="if true, register a SIGTERM signal handler to capture data when the process ends due to a SIGTERM signal.")

# intended for slipcover development only
ap.add_argument('--silent', action='store_true', help=argparse.SUPPRESS)
Expand Down Expand Up @@ -241,6 +243,15 @@ def printit(coverage, outfile):

atexit.register(sci_atexit)

# Windows doesn't have a SIGTERM signal.
if args.sigterm and platform.system() != 'Windows':
def sci_sigterm_atexit(signum, frame):
sci_atexit()
# we have to exit here, otherwise the process won't stop.
sys.exit(0)

signal.signal(signal.SIGTERM, sci_sigterm_atexit)

if args.script:
# python 'globals' for the script being executed
script_globals: Dict[Any, Any] = dict()
Expand Down