mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
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.
This commit is contained in:
parent
8bcfd31cc0
commit
252346acd9
14 changed files with 68 additions and 12 deletions
|
@ -632,6 +632,7 @@ _PyConfig_InitCompatConfig(PyConfig *config)
|
|||
config->check_hash_pycs_mode = NULL;
|
||||
config->pathconfig_warnings = -1;
|
||||
config->_init_main = 1;
|
||||
config->_isolated_interpreter = 0;
|
||||
#ifdef MS_WINDOWS
|
||||
config->legacy_windows_stdio = -1;
|
||||
#endif
|
||||
|
@ -850,6 +851,7 @@ _PyConfig_Copy(PyConfig *config, const PyConfig *config2)
|
|||
COPY_WSTR_ATTR(check_hash_pycs_mode);
|
||||
COPY_ATTR(pathconfig_warnings);
|
||||
COPY_ATTR(_init_main);
|
||||
COPY_ATTR(_isolated_interpreter);
|
||||
|
||||
#undef COPY_ATTR
|
||||
#undef COPY_WSTR_ATTR
|
||||
|
@ -949,6 +951,7 @@ config_as_dict(const PyConfig *config)
|
|||
SET_ITEM_WSTR(check_hash_pycs_mode);
|
||||
SET_ITEM_INT(pathconfig_warnings);
|
||||
SET_ITEM_INT(_init_main);
|
||||
SET_ITEM_INT(_isolated_interpreter);
|
||||
|
||||
return dict;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue