-
-
Notifications
You must be signed in to change notification settings - Fork 448
run: Support system signal as a coverage report dump trigger. #1998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ark-g
wants to merge
1
commit into
nedbat:master
Choose a base branch
from
ark-g:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+36
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,9 +10,11 @@ | |||||
import os | ||||||
import os.path | ||||||
import shlex | ||||||
import signal | ||||||
import sys | ||||||
import textwrap | ||||||
import traceback | ||||||
import types | ||||||
|
||||||
from typing import cast, Any, NoReturn | ||||||
|
||||||
|
@@ -227,7 +229,15 @@ class Opts: | |||||
"", "--version", action="store_true", | ||||||
help="Display version information and exit.", | ||||||
) | ||||||
|
||||||
dump_signal = optparse.make_option( | ||||||
'', '--dump_signal', action='store', metavar='DUMP_SIGNAL', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Options use hyphens, not underscores. |
||||||
choices = ['USR1', 'USR2'], | ||||||
help=( | ||||||
"Define a system signal that will trigger coverage report dump. " + | ||||||
"It is important that target script do not intercept this signal. " + | ||||||
"Currently supported options are: USR1, USR2." | ||||||
), | ||||||
) | ||||||
|
||||||
class CoverageOptionParser(optparse.OptionParser): | ||||||
"""Base OptionParser for coverage.py. | ||||||
|
@@ -251,6 +261,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: | |||||
data_file=None, | ||||||
debug=None, | ||||||
directory=None, | ||||||
dump_signal=None, | ||||||
fail_under=None, | ||||||
format=None, | ||||||
help=None, | ||||||
|
@@ -525,6 +536,7 @@ def get_prog_name(self) -> str: | |||||
Opts.parallel_mode, | ||||||
Opts.source, | ||||||
Opts.timid, | ||||||
Opts.dump_signal, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep these items alphabetized. |
||||||
] + GLOBAL_ARGS, | ||||||
usage="[options] <pyfile> [program options]", | ||||||
description="Run a Python program, measuring code execution.", | ||||||
|
@@ -807,6 +819,11 @@ def do_help( | |||||
|
||||||
return False | ||||||
|
||||||
def do_dump(self, _signum: int, _frame: types.FrameType | None) -> None: | ||||||
""" Signal handler to dump coverage report """ | ||||||
print("Dumping coverage data ...") | ||||||
self.coverage.save() | ||||||
|
||||||
def do_run(self, options: optparse.Values, args: list[str]) -> int: | ||||||
"""Implementation of 'coverage run'.""" | ||||||
|
||||||
|
@@ -851,6 +868,15 @@ def do_run(self, options: optparse.Values, args: list[str]) -> int: | |||||
if options.append: | ||||||
self.coverage.load() | ||||||
|
||||||
if options.dump_signal: | ||||||
if options.dump_signal.upper() == 'USR1': | ||||||
signal.signal(signal.SIGUSR1, self.do_dump) | ||||||
elif options.dump_signal.upper() == 'USR2': | ||||||
signal.signal(signal.SIGUSR2, self.do_dump) | ||||||
else: | ||||||
show_help(f"Unsupported signal for dump coverage report: {options.dump_signal}") | ||||||
return ERR | ||||||
|
||||||
# Run the script. | ||||||
self.coverage.start() | ||||||
code_ran = True | ||||||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I think this should be called "save signal" instead of "dump signal" throughout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These make_option definitions are in rough alphabetical order, so this should be further up.