Skip to content
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

gh-91880: add try/except around signal.signal #91881

Merged
merged 2 commits into from Apr 25, 2022

Conversation

davidhewitt
Copy link
Contributor

@davidhewitt davidhewitt commented Apr 24, 2022

As suggested in #32105 (comment) by @gvanrossum, add a try/except around use of signal.signal to protect against possible exceptions.

try:
signal.signal(signal.SIGINT, sigint_handler)
except ValueError:
pass
Copy link
Member

@gvanrossum gvanrossum Apr 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more comfortable if at this point you set sigint_handler = None. It is not strictly required, but that's more or less an accident of the implementation; setting it to None is a clear signal that no restoration is required at the end (used also below).

In addition, I'd like to see a comment explaining under which circumstances we expect ValueError and what it means (since it wasn't clear to the original author, nor to me, why the tests for applicability of signal handling is not 100% effective).

Copy link
Contributor Author

@davidhewitt davidhewitt Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've pushed a commit to set to None with a comment as requested.

Copy link
Member

@gvanrossum gvanrossum left a comment

Thanks! I'll land now.

@gvanrossum gvanrossum merged commit 1cd8c29 into python:main Apr 25, 2022
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants