gh-150355: Allow creating tasks in cancelled TaskGroup with cooperative cancellation#150357
gh-150355: Allow creating tasks in cancelled TaskGroup with cooperative cancellation#150357azibom wants to merge 1 commit into
Conversation
picnixz
left a comment
There was a problem hiding this comment.
We first need a discussion before a PR. This is premature. Please read the devguide to understand our process.
This also needs:
- A doc change
- What's New.
- NEWS entries.
For now, I'm going to close it. Wait on the issue before re-opening the PR please.
|
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 |
gh-150355: Allow create_task after tg.cancel() – cooperative cancellation
Problem:
After
tg.cancel(),create_task()raisesRuntimeError: TaskGroup is shutting down. The test TODO says this is not ideal – the task should run until the first await and then be cancelled.Solution:
Add
_explicitly_cancelledflag. On explicitcancel()the flag is set. Increate_task(), if_abortingand_explicitly_cancelledis true, the task is created normally and then scheduled for cancellation withcall_soon. This allows the synchronous code up to the firstawaitto run. Failure‑induced abort still raisesRuntimeError.Testing:
All 118 tests in
test_asyncio.test_taskgroupspass.