Skip to content

Commit 4ecb354

Browse files
fix test
1 parent 8e0b360 commit 4ecb354

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/test/test_asyncio/test_free_threading.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def runner():
6262
def test_all_tasks_different_thread(self) -> None:
6363
loop = None
6464
started = threading.Event()
65-
65+
done = threading.Event() # used for main task not finishing early
6666
async def coro():
67-
await asyncio.sleep(0.01)
67+
await asyncio.Future()
6868

6969
lock = threading.Lock()
7070
tasks = set()
@@ -77,6 +77,7 @@ async def main():
7777
with lock:
7878
asyncio.create_task(coro())
7979
tasks = self.all_tasks(loop)
80+
done.wait()
8081

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

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

8889
threads = [threading.Thread(target=check) for _ in range(10)]
89-
threads.append(runner)
90+
runner.start()
9091

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

95+
done.set()
96+
runner.join()
97+
9498
def test_run_coroutine_threadsafe(self) -> None:
9599
results = []
96100

0 commit comments

Comments
 (0)