Skip to content

InterpreterPoolExecutor doesn't respect "thread_name_prefix" #125920

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
paultiq opened this issue Oct 24, 2024 · 1 comment
Open

InterpreterPoolExecutor doesn't respect "thread_name_prefix" #125920

paultiq opened this issue Oct 24, 2024 · 1 comment
Labels
3.14 bugs and security fixes extension-modules C modules in the Modules dir topic-subinterpreters type-bug An unexpected behavior, bug, or error

Comments

@paultiq
Copy link

paultiq commented Oct 24, 2024

Bug report

Bug description:

InterpreterPoolExecutor takes a thread_name_prefix parameter, but it doesn't propagate to the underlying subinterpreter.

from concurrent.futures import ThreadPoolExecutor
try:
    from concurrent.futures.interpreter import InterpreterPoolExecutor # 3.14+
except ModuleNotFoundError:
    from interpreters_backport.concurrent.futures.interpreter import InterpreterPoolExecutor 

with ThreadPoolExecutor(thread_name_prefix="test_tpe") as tpe_executor:
    tpe_executor.submit(exec, "import threading;print(threading.current_thread().name)")  # 
    
with InterpreterPoolExecutor(thread_name_prefix="test_ipe") as ipe_executor:
    ipe_executor.submit(exec, "import threading;print(threading.current_thread().name)")

Produces

test_tpe_0
Dummy-1

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

@paultiq paultiq added the type-bug An unexpected behavior, bug, or error label Oct 24, 2024
@ZeroIntensity ZeroIntensity added stdlib Python modules in the Lib dir topic-subinterpreters labels Oct 24, 2024
@ZeroIntensity
Copy link
Member

ZeroIntensity commented Oct 24, 2024

Confirmed on the main branch, but this isn't related to InterpreterPoolExecutor. ipe_executor._thread_name_prefix does appear to be set to the correct value, and the Thread object name is the right value when checking it directly with ipe_executor._threads.

The problem is that thread names aren't pushed down to subinterpreters, which very well might be a wontfix depending on the complexity of the change. Here's a reproducer for that:

import _interpreters
import threading

source = """
import threading

print(threading.current_thread().name)  # Dummy-1
"""

def main():
    interp = _interpreters.create()
    print(threading.current_thread().name)  # Hello
    _interpreters.run_string(interp, source)

threading.Thread(target=main, name="hello").start()

cc @ericsnowcurrently, it might be better to just note this when subinterpreters get documented better. (Though, if that's the case, thread_name_prefix should just get removed from InterpreterPoolExecutor.)

@ZeroIntensity ZeroIntensity added extension-modules C modules in the Modules dir 3.14 bugs and security fixes and removed stdlib Python modules in the Lib dir labels Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 bugs and security fixes extension-modules C modules in the Modules dir topic-subinterpreters type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

2 participants