Skip to content

Commit

Permalink
gh-128002: fix test_all_tasks_different_thread in asyncio (#129267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 authored Jan 24, 2025
1 parent 7907203 commit e635bf2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Lib/test/test_asyncio/test_free_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def runner():
def test_all_tasks_different_thread(self) -> None:
loop = None
started = threading.Event()

done = threading.Event() # used for main task not finishing early
async def coro():
await asyncio.sleep(0.01)
await asyncio.Future()

lock = threading.Lock()
tasks = set()
Expand All @@ -77,6 +77,7 @@ async def main():
with lock:
asyncio.create_task(coro())
tasks = self.all_tasks(loop)
done.wait()

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

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

threads = [threading.Thread(target=check) for _ in range(10)]
threads.append(runner)
runner.start()

with threading_helper.start_threads(threads):
pass

done.set()
runner.join()

def test_run_coroutine_threadsafe(self) -> None:
results = []

Expand Down

0 comments on commit e635bf2

Please sign in to comment.