python / python/cpython

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

Open
#139,523 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.14 3.15 stdlib topic-subinterpreters type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing concurrent.interpreters.Interpreter.prepare_main() and Interpreter.is_running(), focusing on why preparation is rejected for a running interpreter. Determine whether allowing external changes to main is safe across threads and subinterpreters, then define the behavior and tests needed before changing the restriction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.