-
-
Couldn't load subscription status.
- Fork 33.2k
gh-128552: fix refcycles in eager task creation #128553
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
Changes from 5 commits
c82f30b
8a4eb56
35a38e4
afd3053
9700ebf
fe83add
a1f76df
7c966d0
89362f5
cf5cfe3
18b6ea9
ca71935
cc39717
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 |
|---|---|---|
|
|
@@ -12,11 +12,6 @@ | |
|
|
||
| from test.test_asyncio.utils import await_without_task | ||
|
|
||
| # To prevent a warning "test altered the execution environment" | ||
|
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. I know this isn't needed as you have changed it to use asyncio.EventLoop but let's keep it for now, it is easy to make a mistake on altering policy and is a pain to fix in CI if it happens without this. |
||
| def tearDownModule(): | ||
| asyncio._set_event_loop_policy(None) | ||
|
|
||
|
|
||
| class MyExc(Exception): | ||
graingert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pass | ||
|
|
||
|
|
@@ -38,7 +33,7 @@ def no_other_refs(): | |
| return [coro] | ||
|
|
||
|
|
||
| class TestTaskGroup(unittest.IsolatedAsyncioTestCase): | ||
| class BaseTestTaskGroup: | ||
|
|
||
| async def test_taskgroup_01(self): | ||
|
|
||
|
|
@@ -832,15 +827,15 @@ async def test_taskgroup_without_parent_task(self): | |
| with self.assertRaisesRegex(RuntimeError, "has not been entered"): | ||
| tg.create_task(coro) | ||
|
|
||
| def test_coro_closed_when_tg_closed(self): | ||
| async def test_coro_closed_when_tg_closed(self): | ||
| async def run_coro_after_tg_closes(): | ||
| async with taskgroups.TaskGroup() as tg: | ||
| pass | ||
| coro = asyncio.sleep(0) | ||
| with self.assertRaisesRegex(RuntimeError, "is finished"): | ||
| tg.create_task(coro) | ||
| loop = asyncio.get_event_loop() | ||
| loop.run_until_complete(run_coro_after_tg_closes()) | ||
|
|
||
| await run_coro_after_tg_closes() | ||
|
|
||
| async def test_cancelling_level_preserved(self): | ||
| async def raise_after(t, e): | ||
|
|
@@ -998,5 +993,16 @@ class MyKeyboardInterrupt(KeyboardInterrupt): | |
| self.assertListEqual(gc.get_referrers(exc), no_other_refs()) | ||
|
|
||
|
|
||
| class TestTaskGroup(BaseTestTaskGroup, unittest.IsolatedAsyncioTestCase): | ||
| loop_factory = asyncio.EventLoop | ||
|
|
||
| class TestEagerTaskTaskGroup(BaseTestTaskGroup, unittest.IsolatedAsyncioTestCase): | ||
| @staticmethod | ||
| def loop_factory(): | ||
| loop = asyncio.EventLoop() | ||
| loop.set_task_factory(asyncio.eager_task_factory) | ||
| return loop | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix cyclic garbage introduced by :meth:`loop.create_task` and :meth:`asyncio.TaskGroup.create_task` holding a reference to the created task. | ||
graingert marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.