Skip to content

Commit

Permalink
fix thread safety
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 committed Dec 21, 2024
1 parent 2a66dd3 commit f3642ae
Show file tree
Hide file tree
Showing 3 changed files with 813 additions and 126 deletions.
26 changes: 26 additions & 0 deletions Lib/test/test_asyncio/test_free_threading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import asyncio
from test.support import threading_helper
from unittest import TestCase
from threading import Thread

threading_helper.requires_working_threading(module=True)

class TestFreeThreading(TestCase):
def test_all_tasks_race(self) -> None:
async def task():
await asyncio.sleep(0)

async def main():
async with asyncio.TaskGroup() as tg:
for _ in range(100):
tg.create_task(task())
asyncio.all_tasks()

threads = []
for _ in range(10):
thread = Thread(target=lambda: asyncio.run(main()))
threads.append(thread)

with threading_helper.start_threads(threads):
pass

Loading

0 comments on commit f3642ae

Please sign in to comment.