Skip to content

Commit 0582f94

Browse files
inikolaevfantix
andauthored
Add thread name prefix to the default thread pool executor (#636)
--------- Co-authored-by: Fantix King <fantix.king@gmail.com>
1 parent 963a5f3 commit 0582f94

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

tests/test_base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,26 @@ async def main():
799799
elif result.returncode != 0:
800800
self.fail(result.stdout.strip())
801801

802+
def test_thread_name_prefix_in_default_executor(self):
803+
if self.implementation == "asyncio" and sys.version_info < (3, 9):
804+
raise unittest.SkipTest(
805+
"thread_name_prefix was added in CPython 3.9"
806+
)
807+
808+
called = []
809+
810+
def cb():
811+
called.append(threading.current_thread().name)
812+
813+
async def runner():
814+
await self.loop.run_in_executor(None, cb)
815+
816+
self.loop.run_until_complete(runner())
817+
818+
self.assertEqual(len(called), 1)
819+
self.assertTrue(called[0] is not None)
820+
self.assertTrue(called[0].startswith(self.implementation))
821+
802822

803823
class TestBaseUV(_TestBase, UVTestCase):
804824

uvloop/loop.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,7 @@ cdef class Loop:
27472747
# Only check when the default executor is being used
27482748
self._check_default_executor()
27492749
if executor is None:
2750-
executor = cc_ThreadPoolExecutor()
2750+
executor = cc_ThreadPoolExecutor(thread_name_prefix='uvloop')
27512751
self._default_executor = executor
27522752

27532753
return aio_wrap_future(executor.submit(func, *args), loop=self)

0 commit comments

Comments
 (0)