Skip to content
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

gh-128002: fix test_all_tasks_different_thread in asyncio #129267

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading