Skip to content

gh-136470: Correct InterpreterPoolExecutor's default thread name #136472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions Lib/concurrent/futures/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,7 @@ def __init__(self, max_workers=None, thread_name_prefix='',
each worker interpreter.
initargs: A tuple of arguments to pass to the initializer.
"""
thread_name_prefix = (thread_name_prefix or
(f"InterpreterPoolExecutor-{self._counter()}"))
super().__init__(max_workers, thread_name_prefix,
initializer, initargs)
15 changes: 15 additions & 0 deletions Lib/test/test_concurrent_futures/test_interpreter_pool.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _thread
import asyncio
import contextlib
import io
Expand Down Expand Up @@ -498,6 +499,20 @@ def test_import_interpreter_pool_executor(self):
self.assertEqual(p.stdout.decode(), '')
self.assertEqual(p.stderr.decode(), '')

def test_thread_name_prefix(self):
self.assertStartsWith(self.executor._thread_name_prefix,
"InterpreterPoolExecutor-")

@unittest.skipUnless(hasattr(_thread, '_get_name'), "missing _thread._get_name")
def test_thread_name_prefix_with_thread_get_name(self):
def get_thread_name():
import _thread
return _thread._get_name()

# Some platforms (Linux) are using 16 bytes to store the thread name,
# so only compare the first 15 bytes (without the trailing \n).
self.assertStartsWith(self.executor.submit(get_thread_name).result(),
"InterpreterPoolExecutor-"[:15])

class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Correct :class:`concurrent.futures.InterpreterPoolExecutor`'s default thread
name.
Loading