8000 gh-128002: use per threads tasks linked list in asyncio by kumaraditya303 · Pull Request #128869 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128002: use per threads tasks linked list in asyncio #128869

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

Merged
merged 22 commits into from
Feb 6, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add more tests
  • Loading branch information
kumaraditya303 committed Jan 21, 2025
commit 5f5b95edd5d8813c71e60d2e75f34272024f6177
40 changes: 40 additions & 0 deletions Lib/test/test_asyncio/test_free_threading.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import asyncio
import unittest
import threading
import weakref
from test import support
from threading import Thread
from unittest import TestCase

Expand Down Expand Up @@ -58,6 +61,43 @@ def runner():
with threading_helper.start_threads(threads):
pass

def test_all_tasks_different_thread(self) -> None:
task = None
loop = None
started = threading.Event()
stop = threading.Event()
done = False
async def func():
nonlocal task, loop, done
loop = asyncio.get_running_loop()
task = asyncio.current_task()
started.set()
while not stop.is_set():
await asyncio.sleep(0)

thread = Thread(target=lambda: asyncio.run(func()))
with threading_helper.start_threads([thread]):
started.wait()
self.assertSetEqual(asyncio.all_tasks(loop), {task})
self.assertIs(task.get_loop(), loop)
stop.set()

def test_all_tasks_different_thread_finalized(self) -> None:
task = None
loop = asyncio.EventLoop()
async def func():
nonlocal task
task = asyncio.current_task()

loop.run_until_complete(func())

self.assertEqual(self.all_tasks(loop), set())
wr = weakref.ref(task)
del task
# task finalization in different thread shoudn't crash
support.gc_collect()
self.assertIsNone(wr())

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

Expand Down
Loading
0