Skip to content

Commit 07ac2d6

Browse files
fix test
1 parent aa4c2d1 commit 07ac2d6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/test/test_asyncio/test_free_threading.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def runner():
6363
def test_all_tasks_different_thread(self) -> None:
6464
loop = None
6565
started = threading.Event()
66-
66+
done = threading.Event() # used for main task not finishing early
6767
async def coro():
68-
await asyncio.sleep(0.01)
68+
await asyncio.Future()
6969

7070
lock = threading.Lock()
7171
tasks = set()
@@ -78,6 +78,7 @@ async def main():
7878
with lock:
7979
asyncio.create_task(coro())
8080
tasks = self.all_tasks(loop)
81+
done.wait()
8182

8283
runner = threading.Thread(target=lambda: asyncio.run(main()))
8384

@@ -87,11 +88,14 @@ def check():
8788
self.assertSetEqual(tasks & self.all_tasks(loop), tasks)
8889

8990
threads = [threading.Thread(target=check) for _ in range(10)]
90-
threads.append(runner)
91+
runner.start()
9192

9293
with threading_helper.start_threads(threads):
9394
pass
9495

96+
done.set()
97+
runner.join()
98+
9599
def test_task_different_thread_finalized(self) -> None:
96100
task = None
97101
async def func():

0 commit comments

Comments
 (0)