-
Notifications
You must be signed in to change notification settings - Fork 144
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
Fix #666 handle SIGTERM #712
base: rolling
Are you sure you want to change the base?
Changes from all commits
6b77d00
457159a
9367e65
b1dfecc
63ebbe3
8bd220a
213046d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,6 +235,7 @@ def handle( | |
:return: previous handler if any, otherwise None | ||
""" | ||
signum = signal.Signals(signum) | ||
signal.signal(signum, signal.default_int_handler) | ||
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. @ciandonovan thanks for catching this! I dropped the ball here, my bad. That said, I don't think this is the complete fix. We should only override default signal handlers (chaining non-default ones), and we should restore whatever was in place on 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. In this case I'm not overriding any default handlers, as SIGINT is already handled by Ideally both would be handled by some global _noop function that just passes, letting 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.
Right, but we don't really know which signal number we will be required to handle, and even if we did (or assumed so or constrained it to be such and such), there is also the possibility that some other library, used by 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. So what should we do here? Is it ok to just override any existing signal handler with when this is called? How does this interact with 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. The only existing signal handler at this point is the one the Python binary sets itself for SIGINT to generate the |
||
if handler is not None: | ||
if not callable(handler): | ||
raise ValueError('signal handler must be a callable') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,19 +25,19 @@ | |
|
||
|
||
def cap_signals(*signals): | ||
def _noop(*args): | ||
pass | ||
|
||
def _decorator(func): | ||
@functools.wraps(func) | ||
def _wrapper(*args, **kwargs): | ||
handlers = {} | ||
try: | ||
for s in signals: | ||
handlers[s] = signal.signal(s, _noop) | ||
handlers[s] = signal.signal(s, signal.default_int_handler) | ||
return func(*args, **kwargs) | ||
except KeyboardInterrupt: | ||
pass | ||
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. @ciandonovan hmm, this will skip the entire test with a green check. The 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. Could you clarify why, or what it's interrupting? My understanding is that the 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. Right, those |
||
finally: | ||
assert all(signal.signal(s, h) is _noop for s, h in handlers.items()) | ||
assert all(signal.signal(s, h) is signal.default_int_handler | ||
for s, h in handlers.items()) | ||
return _wrapper | ||
|
||
return _decorator | ||
|
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.
@ciandonovan meta: sending a shutdown event is not the same as pulling the brakes on the event loop, but I can see how the previous implementation can cause problems when managing
launch
itself. Most process managers use SIGTERM. I guess you could argue that SIGKILL escalation is appropriate if a shutdown isn't enough.