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

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Kumar Aditya 2025-02-07 00:21:07 +05:30 committed by GitHub
parent b4ff8b22b3
commit 0d68b14a0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 156 additions and 58 deletions

View file

@ -3,7 +3,8 @@
import unittest
from threading import Thread
from unittest import TestCase
import weakref
from test import support
from test.support import threading_helper
threading_helper.requires_working_threading(module=True)
@ -95,6 +96,22 @@ def check():
done.set()
runner.join()
def test_task_different_thread_finalized(self) -> None:
task = None
async def func():
nonlocal task
task = asyncio.current_task()
thread = Thread(target=lambda: asyncio.run(func()))
thread.start()
thread.join()
wr = weakref.ref(task)
del thread
del task
# task finalization in different thread shouldn't crash
support.gc_collect()
self.assertIsNone(wr())
def test_run_coroutine_threadsafe(self) -> None:
results = []