Skip to content

Allow Interpreter.prepare_main() Even If the Interpreter Is Running? #139523

@ericsnowcurrently

Description

@ericsnowcurrently

Feature or enhancement

Proposal:

Currently Interpreter.prepare_main() (from concurrent.interpreters) fails if the interpreter is running. (See Interpreter.is_running(). It may make sense to relax this restriction.

For example, it might make sense for a subinterpreter to call prepare_main() on the main interpreter to share a cross-interpreter Queue. Currently that fails because the main interpreter is always considered to be "running".
The answer for now is "make sure the main interpreter creates any queues it needs to share" and that might be good enough.

It's something I hadn't considered before and I'm not exactly sure yet that allowing it would be the right thing. The problem is that it isn't intuitively obvious to users (or me) how externally modifying an interpreter's __main__ module may affect code running there in a different thread.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-subinterpreterstype-featureA feature request or enhancement

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions