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. |
ericsnowcurrently
left a comment
There was a problem hiding this comment.
LGTM (maybe could use a few more tests, as noted)
Presumably we will do the PEP 489 check in a separate PR.
| """) | ||
| with file: | ||
| interpreters.run_string(self.id, script) | ||
| interpreters.run_string(subinterp, script) |
There was a problem hiding this comment.
It may be worth having a test that assertRaises() when isolated is True. Likewise for the other restrictions.
| 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.
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