Skip to content

Commit

Permalink
Add thread name prefix to the default thread pool executor
Browse files Browse the repository at this point in the history
  • Loading branch information
inikolaev committed Oct 20, 2024
1 parent 7bb12a1 commit da5cb65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit da5cb65

Please sign in to comment.