Skip to content

Commit 2fb4454

Browse files
committed
moved test from test_free_threading/test_asyncio to test_asyncio/test_free_threading
1 parent af269b9 commit 2fb4454

2 files changed

Lines changed: 39 additions & 48 deletions

File tree

Lib/test/test_asyncio/test_free_threading.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,45 @@ async def main():
165165
loop.set_task_factory(self.factory)
166166
r.run(main())
167167

168+
def test_all_tasks_from_other_thread_includes_eager_tasks(self):
169+
# gh-152020: all_tasks() called from another thread used to drop
170+
# eager-started tasks on free-threaded builds.
171+
loop = asyncio.new_event_loop()
172+
173+
async def _forever():
174+
await asyncio.Event().wait()
175+
176+
def eager_factory(loop, coro, **kwargs):
177+
return self.factory(loop, coro, eager_start=True, **kwargs)
178+
179+
async def setup():
180+
loop.set_task_factory(eager_factory)
181+
eager = loop.create_task(_forever(), name="EAGER")
182+
loop.set_task_factory(None)
183+
normal = loop.create_task(_forever(), name="NORMAL")
184+
return eager, normal
185+
186+
async def teardown():
187+
tasks = [t for t in asyncio.all_tasks()
188+
if t is not asyncio.current_task()]
189+
for t in tasks:
190+
t.cancel()
191+
await asyncio.gather(*tasks, return_exceptions=True)
192+
193+
thread = threading.Thread(target=loop.run_forever)
194+
thread.start()
195+
try:
196+
held = asyncio.run_coroutine_threadsafe(setup(), loop).result()
197+
names = {t.get_name() for t in asyncio.all_tasks(loop)}
198+
self.assertIn("NORMAL", names)
199+
self.assertIn("EAGER", names)
200+
del held
201+
finally:
202+
asyncio.run_coroutine_threadsafe(teardown(), loop).result()
203+
loop.call_soon_threadsafe(loop.stop)
204+
thread.join()
205+
loop.close()
206+
168207

169208
class TestPyFreeThreading(TestFreeThreading, TestCase):
170209

Lib/test/test_free_threading/test_asyncio.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)