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
bpo-40453: Add PyConfig._isolated_subinterpreter #19820
Conversation
An isolated subinterpreter cannot spawn threads, spawn a child process or call os.fork(). * Add private _Py_NewInterpreter(isolated_subinterpreter) function. * Add isolated=True keyword-only parameter to _xxsubinterpreters.create(). * Allow again os.fork() in "non-isolated" subinterpreters.
|
This change is related to https://www.python.org/dev/peps/pep-0554/ PyConfig._isolated_subinterpreter can be used by import to reject C extensions which don't implement multiphase initialization (PEP 489). |
|
@ericsnowcurrently: I chose to aggressively disallow threads and subprocesses. The idea is to only allow them later once we will have more time properly test them once we will have a per-interpreter GIL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (maybe could use a few more tests, as noted)
Presumably we will do the PEP 489 check in a separate PR.
| @@ -824,7 +825,7 @@ def f(): | |||
| t.join() | |||
| """) | |||
| with file: | |||
| interpreters.run_string(self.id, script) | |||
| interpreters.run_string(subinterp, script) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worth having a test that assertRaises() when isolated is True. Likewise for the other restrictions.
| @@ -65,6 +65,8 @@ PyAPI_FUNC(int) _Py_CoerceLegacyLocale(int warn); | |||
| PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn); | |||
| PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category); | |||
|
|
|||
| PyAPI_FUNC(PyThreadState *) _Py_NewInterpreter(int isolated_subinterpreter); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked about, this is a good place to start. :)
An isolated subinterpreter cannot spawn threads, spawn a child
process or call os.fork().
_xxsubinterpreters.create().
https://bugs.python.org/issue40453