-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-155418: Fix TaskGroup hang when a task cancels it before suspending #155421
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1154,6 +1154,20 @@ async def test_taskgroup_cancel_before_create_task(self): | |
| with self.assertRaises(RuntimeError): | ||
| tg.create_task(asyncio.sleep(1)) | ||
|
|
||
| async def test_taskgroup_cancel_from_child_before_first_suspension(self): | ||
| # gh-155418: an eager task can cancel the group before joining _tasks | ||
| done = [] | ||
|
|
||
| async def child(tg): | ||
| tg.cancel() | ||
| await asyncio.sleep(10) | ||
| done.append(True) | ||
|
|
||
| async with asyncio.TaskGroup() as tg: | ||
| task = tg.create_task(child(tg)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use your reproducer with the print as well? could be useful to catch (instead of print, just use a list and mutate it)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! just pushed the changes |
||
| self.assertTrue(task.cancelled()) | ||
| self.assertEqual(done, []) | ||
|
|
||
| async def test_taskgroup_cancel_before_exception(self): | ||
| async def raise_exc(parent_tg: asyncio.TaskGroup): | ||
| parent_tg.cancel() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix :class:`asyncio.TaskGroup` hang when a task cancels it before | ||
| suspending. |
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.
I thought the problem was with the eager task factory?
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.
hi! if i understand you well - BaseTestTaskGroup class that stores all of the tests is not inheriting from unittests TestCase https://github.com/deadlovelll/cpython/blob/62ab3f87bdb17aafa97e44fd26386893ead0497b/Lib/test/test_asyncio/test_taskgroups.py#L60.
Runners are TestTaskGroup and TestEagerTaskTaskGroup that inherits from BaseTestTaskGroup and unittest.IsolatedAsyncioTestCase, they are located at the bottom of the file https://github.com/deadlovelll/cpython/blob/62ab3f87bdb17aafa97e44fd26386893ead0497b/Lib/test/test_asyncio/test_taskgroups.py#L1307-L1315
TestEagerTaskTaskGroup already inject eager factory for this