Skip to content

InterpreterPoolExecutor doesn't respect "thread_name_prefix" #125920

Description

@paultiq

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

Activity

  1. ZeroIntensity commented on Oct 24, 2024

    @ZeroIntensity
    Member

    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.)

  2. added
    3.14bugs and security fixes
    and removed
    stdlibStandard Library Python modules in the Lib/ directory
    on Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions