Skip to content

Commit 6b2f44e

Browse files
[3.11] GH-109067: fix randomly failing test_async_gen_asyncio_gc_aclose_09 test (GH-109142) (#109150)
GH-109067: fix randomly failing `test_async_gen_asyncio_gc_aclose_09` test (GH-109142) Use `asyncio.sleep(0)` instead of short sleeps. (cherry picked from commit ccd4862) Co-authored-by: Kumar Aditya <[email protected]>
1 parent c1a2ef5 commit 6b2f44e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Lib/test/test_asyncgen.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,7 @@ async def gen():
10371037
while True:
10381038
yield 1
10391039
finally:
1040-
await asyncio.sleep(0.01)
1041-
await asyncio.sleep(0.01)
1040+
await asyncio.sleep(0)
10421041
DONE = 1
10431042

10441043
async def run():
@@ -1048,7 +1047,10 @@ async def run():
10481047
del g
10491048
gc_collect() # For PyPy or other GCs.
10501049

1051-
await asyncio.sleep(0.1)
1050+
# Starts running the aclose task
1051+
await asyncio.sleep(0)
1052+
# For asyncio.sleep(0) in finally block
1053+
await asyncio.sleep(0)
10521054

10531055
self.loop.run_until_complete(run())
10541056
self.assertEqual(DONE, 1)

0 commit comments

Comments
 (0)