From 07e9af55f4b4d679c021c2d39d6162ab446a283c Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 10 Jul 2025 00:06:27 +0900 Subject: [PATCH 1/8] Fix thread_name_prefix for InterpreterPoolExecutor --- Lib/concurrent/futures/interpreter.py | 2 ++ 1 file changed, 2 insertions(+) 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) From 092b63218838446c933ff8f1790275b85fbfbbf9 Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 10 Jul 2025 00:53:49 +0900 Subject: [PATCH 2/8] Add test --- Lib/test/test_concurrent_futures/test_interpreter_pool.py | 4 ++++ .../Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py b/Lib/test/test_concurrent_futures/test_interpreter_pool.py index d5c032d01cdf5d..79c837e9d74e11 100644 --- a/Lib/test/test_concurrent_futures/test_interpreter_pool.py +++ b/Lib/test/test_concurrent_futures/test_interpreter_pool.py @@ -498,6 +498,10 @@ 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-") + 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..7bd27249d7625b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst @@ -0,0 +1,2 @@ +Fix :class:`concurrent.futures.InterpreterPoolExecutor`'s custom thread +name. From 8abaaf6d9821073769276e06eb16befe77ed618f Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 10 Jul 2025 01:34:10 +0900 Subject: [PATCH 3/8] Update test --- Lib/test/test_concurrent_futures/test_interpreter_pool.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py b/Lib/test/test_concurrent_futures/test_interpreter_pool.py index 79c837e9d74e11..bae2c75543fc7e 100644 --- a/Lib/test/test_concurrent_futures/test_interpreter_pool.py +++ b/Lib/test/test_concurrent_futures/test_interpreter_pool.py @@ -502,6 +502,13 @@ def test_thread_name_prefix(self): self.assertStartsWith(self.executor._thread_name_prefix, "InterpreterPoolExecutor-") + def f(): + import _thread + return _thread._get_name() + + self.assertStartsWith(self.executor.submit(f).result(), + "InterpreterPoolExecutor-") + class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase): From 1163b4dea340c5e1cade94247017f839a49650c5 Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 10 Jul 2025 01:35:54 +0900 Subject: [PATCH 4/8] Update Misc/NEWS.d/next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst --- .../next/Library/2025-07-10-00-47-37.gh-issue-136470.KlUEUG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 7bd27249d7625b..5a0429cae07168 100644 --- 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 @@ -1,2 +1,2 @@ -Fix :class:`concurrent.futures.InterpreterPoolExecutor`'s custom thread +Correct :class:`concurrent.futures.InterpreterPoolExecutor`'s default thread name. From c0554688d342af5aad8f4985ea1814923cf99db3 Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 10 Jul 2025 21:07:19 +0900 Subject: [PATCH 5/8] Fix test on non-supported platform --- Lib/test/test_concurrent_futures/test_interpreter_pool.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py b/Lib/test/test_concurrent_futures/test_interpreter_pool.py index bae2c75543fc7e..705a5fee43635d 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 @@ -502,6 +503,8 @@ 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 f(): import _thread return _thread._get_name() From affe63eb19c99b2f89640aa2b296b7be138c460f Mon Sep 17 00:00:00 2001 From: AN Long Date: Thu, 10 Jul 2025 21:17:40 +0900 Subject: [PATCH 6/8] Fix test on Linux --- Lib/test/test_concurrent_futures/test_interpreter_pool.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py b/Lib/test/test_concurrent_futures/test_interpreter_pool.py index 705a5fee43635d..f10d02147f2936 100644 --- a/Lib/test/test_concurrent_futures/test_interpreter_pool.py +++ b/Lib/test/test_concurrent_futures/test_interpreter_pool.py @@ -509,9 +509,10 @@ def f(): 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(f).result(), - "InterpreterPoolExecutor-") - + "InterpreterPoolExecutor-"[:15]) class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase): From 2a690bd1153466d52f2a2424f851d3556da8adb7 Mon Sep 17 00:00:00 2001 From: AN Long Date: Fri, 11 Jul 2025 22:47:01 +0900 Subject: [PATCH 7/8] Update test --- Lib/test/test_concurrent_futures/test_interpreter_pool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py b/Lib/test/test_concurrent_futures/test_interpreter_pool.py index f10d02147f2936..61f2fe545ef5eb 100644 --- a/Lib/test/test_concurrent_futures/test_interpreter_pool.py +++ b/Lib/test/test_concurrent_futures/test_interpreter_pool.py @@ -505,7 +505,7 @@ def test_thread_name_prefix(self): @unittest.skipUnless(hasattr(_thread, '_get_name'), "missing _thread._get_name") def test_thread_name_prefix_with_thread_get_name(self): - def f(): + def get_thread_name(): import _thread return _thread._get_name() From 43da83fc56bdf1777fffff794422a41d839c75df Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 12 Jul 2025 00:46:55 +0900 Subject: [PATCH 8/8] Fix test --- Lib/test/test_concurrent_futures/test_interpreter_pool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_concurrent_futures/test_interpreter_pool.py b/Lib/test/test_concurrent_futures/test_interpreter_pool.py index 61f2fe545ef5eb..7241fcc4b1e74d 100644 --- a/Lib/test/test_concurrent_futures/test_interpreter_pool.py +++ b/Lib/test/test_concurrent_futures/test_interpreter_pool.py @@ -511,7 +511,7 @@ def get_thread_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(f).result(), + self.assertStartsWith(self.executor.submit(get_thread_name).result(), "InterpreterPoolExecutor-"[:15]) class AsyncioTest(InterpretersMixin, testasyncio_utils.TestCase): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy