https://github.com/python/cpython/commit/246be21de1e2a51d757c747902108dfec13e0605
commit: 246be21de1e2a51d757c747902108dfec13e0605
branch: main
author: AN Long <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2025-07-20T23:34:32Z
summary:
gh-136470: Correct InterpreterPoolExecutor's default thread name (GH-136472)
The OS thread name is now correctly prefixed with `InterpreterPoolExecutor`
instead of `ThreadPoolExecutor`.
files:
A Misc/NEWS.d/next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst
M Lib/concurrent/futures/interpreter.py
M Lib/test/test_concurrent_futures/test_interpreter_pool.py
diff --git a/Lib/concurrent/futures/interpreter.py
b/Lib/concurrent/futures/interpreter.py
index cbb60ce80c1813..53c6e757ded2e3 100644
--- a/Lib/concurrent/futures/interpreter.py
+++ b/Lib/concurrent/futures/interpreter.py
@@ -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)
diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py
b/Lib/test/test_concurrent_futures/test_interpreter_pool.py
index d5c032d01cdf5d..7241fcc4b1e74d 100644
--- a/Lib/test/test_concurrent_futures/test_interpreter_pool.py
+++ b/Lib/test/test_concurrent_futures/test_interpreter_pool.py
@@ -1,3 +1,4 @@
+import _thread
import asyncio
import contextlib
import io
@@ -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):
diff --git
a/Misc/NEWS.d/next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst
b/Misc/NEWS.d/next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst
new file mode 100644
index 00000000000000..5a0429cae07168
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst
@@ -0,0 +1,2 @@
+Correct :class:`concurrent.futures.InterpreterPoolExecutor`'s default thread
+name.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]