Skip to content

bpo-42340: Document issues around KeyboardInterrupt #23255

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

Merged
merged 4 commits into from
Mar 29, 2022

Conversation

benfogle
Copy link
Contributor

@benfogle benfogle commented Nov 13, 2020

Update documentation to note that in some circumstances,
KeyboardInterrupt may cause code to enter an inconsistent state. Also
document sample workaround to avoid KeyboardInterrupt, if needed.

https://bugs.python.org/issue42340

Update documentation to note that in some circumstances,
KeyboardInterrupt may cause code to enter an inconsistent state. Also
document sample workaround to avoid KeyboardInterrupt, if needed.

Because it can be raised at unpredictable points, a KeyboardInterrupt
may, in some circumstances, leave the running program in an inconsistent
state. See :ref:`handlers-and-exceptions`.
Copy link
Member

Choose a reason for hiding this comment

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

This needs clarification that it only applies in cases where KeyboardInterrupt is caught. Otherwise people will become afraid to press Ctrl-C...

I'd also directly mention what to do: "... you should not try to catch KeyboardInterrupt and continue, but let it end the program as quickly as possible, or avoid raising it completely (see ...)"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the pull request.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@birkenfeld birkenfeld dismissed their stale review November 13, 2020 19:16

addressed

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Dec 16, 2020
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, and sorry it's been waiting for so long! I'm happy to help merge this but have a few comments.


If a signal handler raises an exception, the exception will be propagated to
the main thread and may be raised after any :term:`bytecode` instruction. Most
notably, a :exc:`KeyboardInterrupt` may appear at any point during execution.
Copy link
Member

Choose a reason for hiding this comment

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

The example in your issue (KeyboardInterrupt in the middle of an __enter__ was very helpful for me in understanding the problem. What do you think of adding it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a simple example after this paragraph.

@JelleZijlstra JelleZijlstra added needs backport to 3.9 only security fixes needs backport to 3.10 only security fixes labels Mar 24, 2022
@JelleZijlstra JelleZijlstra self-assigned this Mar 26, 2022
@JelleZijlstra
Copy link
Member

Thanks! I'll merge this in a few days unless another core dev comes along and has concerns.

@JelleZijlstra JelleZijlstra merged commit d0906c9 into python:main Mar 29, 2022
@miss-islington
Copy link
Contributor

Thanks @benfogle for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @benfogle and @JelleZijlstra, I had trouble checking out the 3.10 backport branch.
Please backport using cherry_picker on command line.
cherry_picker d0906c90fcfbc4cfb9bb963eaa6bb152dd543b56 3.10

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Mar 29, 2022
@bedevere-bot
Copy link

GH-32184 is a backport of this pull request to the 3.9 branch.

@JelleZijlstra JelleZijlstra added needs backport to 3.10 only security fixes and removed needs backport to 3.10 only security fixes labels Mar 29, 2022
@miss-islington
Copy link
Contributor

Thanks @benfogle for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-32185 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Mar 29, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 29, 2022
Update documentation to note that in some circumstances,
KeyboardInterrupt may cause code to enter an inconsistent state. Also
document sample workaround to avoid KeyboardInterrupt, if needed.
(cherry picked from commit d0906c9)

Co-authored-by: benfogle <benfogle@gmail.com>
miss-islington added a commit that referenced this pull request Mar 29, 2022
Update documentation to note that in some circumstances,
KeyboardInterrupt may cause code to enter an inconsistent state. Also
document sample workaround to avoid KeyboardInterrupt, if needed.
(cherry picked from commit d0906c9)

Co-authored-by: benfogle <benfogle@gmail.com>
miss-islington added a commit that referenced this pull request Mar 29, 2022
Update documentation to note that in some circumstances,
KeyboardInterrupt may cause code to enter an inconsistent state. Also
document sample workaround to avoid KeyboardInterrupt, if needed.
(cherry picked from commit d0906c9)

Co-authored-by: benfogle <benfogle@gmail.com>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
Update documentation to note that in some circumstances,
KeyboardInterrupt may cause code to enter an inconsistent state. Also
document sample workaround to avoid KeyboardInterrupt, if needed.
(cherry picked from commit d0906c9)

Co-authored-by: benfogle <benfogle@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants