Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions Lib/test/test_asyncio/test_eager_task_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,15 @@ class PyEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase
Task = tasks._PyTask

def setUp(self):
self._all_tasks = asyncio.all_tasks
self._current_task = asyncio.current_task
asyncio.current_task = asyncio.tasks.current_task = asyncio.tasks._py_current_task
asyncio.all_tasks = asyncio.tasks.all_tasks = asyncio.tasks._py_all_tasks
return super().setUp()

def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task = self._current_task
asyncio.all_tasks = asyncio.tasks.all_tasks = self._all_tasks
return super().tearDown()


Expand All @@ -285,11 +288,14 @@ class CEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase)

def setUp(self):
self._current_task = asyncio.current_task
self._all_tasks = asyncio.all_tasks
asyncio.current_task = asyncio.tasks.current_task = asyncio.tasks._c_current_task
asyncio.all_tasks = asyncio.tasks.all_tasks = asyncio.tasks._c_all_tasks
return super().setUp()

def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task = self._current_task
asyncio.all_tasks = asyncio.tasks.all_tasks = self._all_tasks
return super().tearDown()


Expand Down
26 changes: 21 additions & 5 deletions Lib/test/test_asyncio/test_free_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def coro():
for _ in range(100):
tasks.add(tg.create_task(coro()))

all_tasks = self.all_tasks(loop)
all_tasks = asyncio.all_tasks(loop)
self.assertEqual(len(all_tasks), 101)

for task in all_tasks:
Expand Down Expand Up @@ -77,15 +77,15 @@ async def main():
for i in range(1000):
with lock:
asyncio.create_task(coro())
tasks = self.all_tasks(loop)
tasks = asyncio.all_tasks(loop)
done.wait()

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

def check():
started.wait()
with lock:
self.assertSetEqual(tasks & self.all_tasks(loop), tasks)
self.assertSetEqual(tasks & asyncio.all_tasks(loop), tasks)

threads = [threading.Thread(target=check) for _ in range(10)]
runner.start()
Expand Down Expand Up @@ -167,15 +167,23 @@ async def main():


class TestPyFreeThreading(TestFreeThreading, TestCase):
all_tasks = staticmethod(asyncio.tasks._py_all_tasks)

def setUp(self):
self._old_current_task = asyncio.current_task
asyncio.current_task = asyncio.tasks.current_task = asyncio.tasks._py_current_task
self._old_all_tasks = asyncio.all_tasks
asyncio.all_tasks = asyncio.tasks.all_tasks = asyncio.tasks._py_all_tasks
self._old_Task = asyncio.Task
asyncio.Task = asyncio.tasks.Task = asyncio.tasks._PyTask
self._old_Future = asyncio.Future
asyncio.Future = asyncio.futures.Future = asyncio.futures._PyFuture
return super().setUp()

def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task = self._old_current_task
asyncio.all_tasks = asyncio.tasks.all_tasks = self._old_all_tasks
asyncio.Task = asyncio.tasks.Task = self._old_Task
asyncio.Future = asyncio.tasks.Future = self._old_Future
return super().tearDown()

def factory(self, loop, coro, **kwargs):
Expand All @@ -184,15 +192,23 @@ def factory(self, loop, coro, **kwargs):

@unittest.skipUnless(hasattr(asyncio.tasks, "_c_all_tasks"), "requires _asyncio")
class TestCFreeThreading(TestFreeThreading, TestCase):
all_tasks = staticmethod(getattr(asyncio.tasks, "_c_all_tasks", None))

def setUp(self):
self._old_current_task = asyncio.current_task
asyncio.current_task = asyncio.tasks.current_task = asyncio.tasks._c_current_task
self._old_all_tasks = asyncio.all_tasks
asyncio.all_tasks = asyncio.tasks.all_tasks = asyncio.tasks._c_all_tasks
self._old_Task = asyncio.Task
asyncio.Task = asyncio.tasks.Task = asyncio.tasks._CTask
self._old_Future = asyncio.Future
asyncio.Future = asyncio.futures.Future = asyncio.futures._CFuture
return super().setUp()

def tearDown(self):
asyncio.current_task = asyncio.tasks.current_task = self._old_current_task
asyncio.all_tasks = asyncio.tasks.all_tasks = self._old_all_tasks
asyncio.Task = asyncio.tasks.Task = self._old_Task
asyncio.Future = asyncio.futures.Future = self._old_Future
return super().tearDown()


Expand Down
Loading