From da5cb65f3e9cc02523e2f0877d1c08fa635d8af9 Mon Sep 17 00:00:00 2001 From: Igor Nikolaev Date: Sun, 20 Oct 2024 21:23:42 +0300 Subject: [PATCH 1/2] Add thread name prefix to the default thread pool executor --- tests/test_base.py | 15 +++++++++++++++ uvloop/loop.pyx | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_base.py b/tests/test_base.py index 86bbd1d0..8e6fbe27 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -869,6 +869,21 @@ def test_loop_call_later_handle_when_after_fired(self): self.loop.run_until_complete(fut) self.assertEqual(handle.when(), when) + def test_thread_name_prefix_in_default_executor(self): + called = [] + + def cb(): + called.append(threading.current_thread().name) + + async def runner(): + await self.loop.run_in_executor(None, cb) + + self.loop.run_until_complete(runner()) + + self.assertEqual(len(called), 1) + self.assertTrue(called[0] is not None) + self.assertTrue(called[0].startswith("uvloop")) + class TestBaseAIO(_TestBase, AIOTestCase): pass diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index f9a5a239..d6e18709 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -2741,7 +2741,7 @@ cdef class Loop: # Only check when the default executor is being used self._check_default_executor() if executor is None: - executor = cc_ThreadPoolExecutor() + executor = cc_ThreadPoolExecutor(thread_name_prefix='uvloop') self._default_executor = executor return aio_wrap_future(executor.submit(func, *args), loop=self) From 6e48794b031775f4726d0f9c1f21b5f096bff10f Mon Sep 17 00:00:00 2001 From: Fantix King Date: Mon, 4 May 2026 11:13:20 -0400 Subject: [PATCH 2/2] Move the test to cover asyncio too --- tests/test_base.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index ceff31d4..69a70677 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -799,6 +799,26 @@ async def main(): elif result.returncode != 0: self.fail(result.stdout.strip()) + def test_thread_name_prefix_in_default_executor(self): + if self.implementation == "asyncio" and sys.version_info < (3, 9): + raise unittest.SkipTest( + "thread_name_prefix was added in CPython 3.9" + ) + + called = [] + + def cb(): + called.append(threading.current_thread().name) + + async def runner(): + await self.loop.run_in_executor(None, cb) + + self.loop.run_until_complete(runner()) + + self.assertEqual(len(called), 1) + self.assertTrue(called[0] is not None) + self.assertTrue(called[0].startswith(self.implementation)) + class TestBaseUV(_TestBase, UVTestCase): @@ -938,21 +958,6 @@ def test_loop_call_later_handle_when_after_fired(self): self.loop.run_until_complete(fut) self.assertEqual(handle.when(), when) - def test_thread_name_prefix_in_default_executor(self): - called = [] - - def cb(): - called.append(threading.current_thread().name) - - async def runner(): - await self.loop.run_in_executor(None, cb) - - self.loop.run_until_complete(runner()) - - self.assertEqual(len(called), 1) - self.assertTrue(called[0] is not None) - self.assertTrue(called[0].startswith("uvloop")) - class TestBaseAIO(_TestBase, AIOTestCase): pass