Skip to content

gh-98608: Change _Py_NewInterpreter() to _Py_NewInterpreterFromConfig()#98609

Merged
ericsnowcurrently merged 16 commits intopython:mainfrom
ericsnowcurrently:interpreter-config
Oct 26, 2022
Merged

gh-98608: Change _Py_NewInterpreter() to _Py_NewInterpreterFromConfig()#98609
ericsnowcurrently merged 16 commits intopython:mainfrom
ericsnowcurrently:interpreter-config

Conversation

@ericsnowcurrently
Copy link
Copy Markdown
Member

@ericsnowcurrently ericsnowcurrently commented Oct 24, 2022

(Note that this PR adds "private" symbols. We'll probably make them public, and add docs, in a separate change.)

We do the following:

  1. change the argument to a new _PyInterpreterConfig struct
  2. rename the function to _Py_NewInterpreterFromConfig(), inspired by Py_InitializeFromConfig() (takes a _PyInterpreterConfig instead of isolated_subinterpreter)
  3. split up the boolean isolated_subinterpreter into the corresponding multiple granular settings
    • allow_fork
    • allow_subprocess
    • allow_threads
  4. add PyInterpreterState.feature_flags to store those settings
  5. add a function for checking if a feature is enabled on an opaque PyInterpreterState *
  6. drop PyConfig._isolated_interpreter

The current default (Py_NewInterpeter() and Py_Initialize*()) allows fork, subprocess, and threads and the optional "isolated" interpreter disables all three. None of that changes here.

Note that the given _PyInterpreterConfig will not be used (nor preserved, for now) outside _Py_NewInterpreterFromConfig(). This contrasts with how PyConfig is currently preserved, used, and modified outside Py_InitializeFromConfig(). I'd rather just avoid that mess from the start for _PyInterpreterConfig.

This change allows us to follow up with a number of improvements (e.g. stop disallowing subprocess and support disallowing exec instead).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants