Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-128588: gh-128550: remove eager tasks optimization that missed and introduced incorrect cancellations#129063
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
kumaraditya303 merged 7 commits into python:main from graingert:fix-eager-tasks-early-callbackJan 20, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits Select commit Hold shift + click to select a range
9fce599 gh-128588: gh-128550: remove eager tasks optimization that missed and…
graingert 73042cf 📜🤖 Added by blurb_it.
blurb-it[bot] 867bacb Update Lib/test/test_asyncio/test_taskgroups.py
graingert c460fa9 Update Lib/test/test_asyncio/test_taskgroups.py
graingert 187abc7 Update Misc/NEWS.d/next/Library/2025-01-20-13-12-39.gh-issue-128550.A…
graingert 874f758 Update Lib/test/test_asyncio/test_taskgroups.py
kumaraditya303 74ef5cc Update Misc/NEWS.d/next/Library/2025-01-20-13-12-39.gh-issue-128550.A…
kumaraditya303 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1041,6 +1041,56 @@ class MyKeyboardInterrupt(KeyboardInterrupt): | ||
| self.assertListEqual(gc.get_referrers(exc), no_other_refs()) | ||
| async def test_cancels_task_if_created_during_creation(self): | ||
| # regression test for gh-128550 | ||
| ran = False | ||
| class MyError(Exception): | ||
| pass | ||
| exc = None | ||
| try: | ||
| async with asyncio.TaskGroup() as tg: | ||
| async def third_task(): | ||
| raise MyError("third task failed") | ||
| async def second_task(): | ||
| nonlocal ran | ||
| tg.create_task(third_task()) | ||
| with self.assertRaises(asyncio.CancelledError): | ||
| await asyncio.sleep(0) # eager tasks cancel here | ||
| await asyncio.sleep(0) # lazy tasks cancel here | ||
| ran = True | ||
| tg.create_task(second_task()) | ||
| except* MyError as excs: | ||
| exc = excs.exceptions[0] | ||
| self.assertTrue(ran) | ||
| self.assertIsInstance(exc, MyError) | ||
| async def test_cancellation_does_not_leak_out_of_tg(self): | ||
| class MyError(Exception): | ||
| pass | ||
| async def throw_error(): | ||
| raise MyError | ||
| try: | ||
| async with asyncio.TaskGroup() as tg: | ||
| tg.create_task(throw_error()) | ||
| except* MyError: | ||
| pass | ||
graingert marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| else: | ||
| self.fail("should have raised one MyError in group") | ||
| # if this test fails this current task will be cancelled | ||
| # outside the task group and inside unittest internals | ||
| # we yield to the event loop with sleep(0) so that | ||
| # cancellation happens here and error is more understandable | ||
| await asyncio.sleep(0) | ||
graingert marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| class TestTaskGroup(BaseTestTaskGroup, unittest.IsolatedAsyncioTestCase): | ||
| loop_factory = asyncio.EventLoop | ||
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2025-01-20-13-12-39.gh-issue-128550.AJ5TOL.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Removed an incorrect optimization relating to eager tasks in :class:`asyncio.TaskGroup` that resulted in cancellations being missed. |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.