Skip to content

gh-108549: In asyncio, do not cancel the current task in Task.__step when a SystemExit exception was just raised - #156309

Open
YvesDup wants to merge 9 commits into
python:mainfrom
YvesDup:asyncio.gather-dont-raise-systemexit
Open

gh-108549: In asyncio, do not cancel the current task in Task.__step when a SystemExit exception was just raised #156309
YvesDup wants to merge 9 commits into
python:mainfrom
YvesDup:asyncio.gather-dont-raise-systemexit

Conversation

@YvesDup

@YvesDup YvesDup commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Modify the asyncio.Task.__step method to prevent a new CancelledErrorto be set when the current task must be cancelled and aSystemExitor a KeybordInterrupt exception is just raised.

The fix should also be pplied in the _asyncio module.

- Update `Task.__step`
,
- Update `_asyncio` module on the corresponding function,
- Add a `test_step_dont_swallow_systemexit`  test in  `test_task.py` file.
@kumaraditya303

Copy link
Copy Markdown
Contributor

This needs a news entry and added comments should be on a single line each if they are short.

@YvesDup

YvesDup commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

@kumaraditya303 : Perharps this words are better for the news file:

"Just before the wrapped coroutine is executed (via the __step method of :class:asyncio.Task) do not cancel the current task if a SystemExit exception (or a KeyboardInterrupt exception) has already been raised."

Comment thread Lib/asyncio/tasks.py Outdated
Comment thread Lib/test/test_asyncio/test_tasks.py Outdated
Comment thread Misc/NEWS.d/next/Library/2026-08-24-14-28-47.gh-issue-108549.XZ34WD.rst Outdated
Comment thread Lib/test/test_asyncio/test_tasks.py
Comment thread Lib/test/test_asyncio/test_tasks.py Outdated
Comment thread Modules/_asynciomodule.c Outdated
@kumaraditya303

Copy link
Copy Markdown
Contributor

Please don't resolve comments until you have pushed changes for them.

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.

2 participants