diff options
author | Victor Stinner <vstinner@python.org> | 2020-05-01 09:33:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-01 09:33:44 (GMT) |
commit | 252346acd937ddba4845331994b8ff4f90349625 (patch) | |
tree | 71d6298db81733d652abaa510c09ba90078efff0 /Python/pylifecycle.c | |
parent | 8bcfd31cc01e068bca78aa42a87c24aea6ebc6b1 (diff) | |
download | cpython-252346acd937ddba4845331994b8ff4f90349625.zip cpython-252346acd937ddba4845331994b8ff4f90349625.tar.gz cpython-252346acd937ddba4845331994b8ff4f90349625.tar.bz2 |
bpo-40453: Add PyConfig._isolated_subinterpreter (GH-19820)
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.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 7909cdb..5726a55 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1526,7 +1526,7 @@ Py_Finalize(void) */ static PyStatus -new_interpreter(PyThreadState **tstate_p) +new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter) { PyStatus status; @@ -1573,6 +1573,7 @@ new_interpreter(PyThreadState **tstate_p) if (_PyStatus_EXCEPTION(status)) { goto error; } + interp->config._isolated_interpreter = isolated_subinterpreter; status = pycore_interp_init(tstate); if (_PyStatus_EXCEPTION(status)) { @@ -1606,10 +1607,10 @@ error: } PyThreadState * -Py_NewInterpreter(void) +_Py_NewInterpreter(int isolated_subinterpreter) { PyThreadState *tstate = NULL; - PyStatus status = new_interpreter(&tstate); + PyStatus status = new_interpreter(&tstate, isolated_subinterpreter); if (_PyStatus_EXCEPTION(status)) { Py_ExitStatusException(status); } @@ -1617,6 +1618,12 @@ Py_NewInterpreter(void) } +PyThreadState * +Py_NewInterpreter(void) +{ + return _Py_NewInterpreter(0); +} + /* Delete an interpreter and its last thread. This requires that the given thread state is current, that the thread has no remaining frames, and that it is its interpreter's only remaining thread. |