GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-146194: Fix nested KeyboardInterrupt handling in asyncio by okiemute04 · Pull Request #146203 · python/cpython

Conversation

@okiemute04

@okiemute04 okiemute04 commented Mar 20, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #146194

Problem

When multiple Ctrl+C presses occurred in nested asyncio tasks, the
third press would cause a crash with "Task was destroyed but it is pending!"
instead of gracefully cancelling the nested tasks.

Solution

Modified _on_sigint in Lib/asyncio/runners.py to cancel the main task
on every SIGINT, allowing nested cancellations to propagate correctly
through multiple levels.

Testing

  • Added test_nested_keyboardinterrupt_handling to test_runners.py
  • Verified that multiple cancellations work correctly without crashes
  • All existing runner tests pass
  • Issue: Asyncio does not handle nested KeyboardInterrupt correctly #146194

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@okiemute04
pythongh-146194: Fix nested KeyboardInterrupt handling in asyncio
2976259
- Modify _on_sigint to cancel main task on every SIGINT
- Allow nested cancellations to propagate correctly through multiple levels
- Add test_nested_keyboardinterrupt_handling to test_runners.py
- Add NEWS entry

Fixes issue where third Ctrl+C would crash with:
'Task was destroyed but it is pending!'
@okiemute04
okiemute04 requested review from 1st1, asvetlov, kumaraditya303 and willingc as code owners March 20, 2026 11:27
@bedevere-app bedevere-app Bot added the awaiting review label Mar 20, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Mar 20, 2026
Asyncio does not handle nested KeyboardInterrupt correctly #146194
Closed
@okiemute04
okiemute04 force-pushed the fix-asyncio-nested-keyboardinterrupt branch from ba59a54 to bd97ffd Compare March 20, 2026 11:43
@okiemute04
pythongh-146194: Fix nested KeyboardInterrupt handling in asyncio
5982498
- Modify _on_sigint to cancel main task on every SIGINT
- Allow nested cancellations to propagate correctly through multiple levels
- Add test_nested_keyboardinterrupt_handling to test_runners.py
- Add NEWS entry

Fixes issue where third Ctrl+C would crash with:
'Task was destroyed but it is pending!'
@okiemute04
okiemute04 force-pushed the fix-asyncio-nested-keyboardinterrupt branch from bd97ffd to 5982498 Compare March 20, 2026 11:48
@okiemute04
Trigger docs rebuild
2563ac4
@okiemute04
okiemute04 force-pushed the fix-asyncio-nested-keyboardinterrupt branch from ce191ae to 2563ac4 Compare March 20, 2026 12:13
@aisk

aisk commented Mar 20, 2026

Copy link
Copy Markdown
Member

Hi, please don't force push, see yesterday's comment: #146179 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aisk
aisk reviewed Mar 20, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-03-20-05-10-21.gh-issue-146194.aXjDnd.rst Outdated
Comment on lines +1 to +4
.. gh-issue: 146194

.. section: Library

@aisk aisk Mar 20, 2026

Copy link
Copy Markdown
Member

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.

There are the same error as #146179

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@okiemute04

okiemute04 commented Mar 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@aisk thanks, I will not anymore. Noted, I was trying to fix the NEWS file issue. I will avoid force pushing going forward.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

okiemute04 added 2 commits March 20, 2026 06:18
@okiemute04
Fix NEWS file formatting - remove duplicate metadata
099cf04
@okiemute04
Add NEWS entry for asyncio nested KeyboardInterrupt fix
034c9af
@picnixz

picnixz commented Mar 20, 2026

Copy link
Copy Markdown
Member

Please do not create PRs if there is no consensus on the issue or if it has not been triaged.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz closed this Mar 20, 2026
@picnixz

picnixz commented Mar 20, 2026

Copy link
Copy Markdown
Member

In addition read our policy on LLM agents. If you do not follow it we will restrict your access.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@okiemute04

okiemute04 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

@picnixz Thanks for the feedback. I do appreciate it. From now on, I will wait for issues to be triaged before commenting on them in the future.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@aisk aisk aisk left review comments
@1st1 1st1 Awaiting requested review from 1st1 1st1 is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Asyncio does not handle nested KeyboardInterrupt correctly

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@okiemute04 @aisk @picnixz
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.