mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-98610: Adjust the Optional Restrictions on Subinterpreters (GH-98618)
Previously, the optional restrictions on subinterpreters were: disallow fork, subprocess, and threads. By default, we were disallowing all three for "isolated" interpreters. We always allowed all three for the main interpreter and those created through the legacy `Py_NewInterpreter()` API. Those settings were a bit conservative, so here we've adjusted the optional restrictions to: fork, exec, threads, and daemon threads. The default for "isolated" interpreters disables fork, exec, and daemon threads. Regular threads are allowed by default. We continue always allowing everything For the main interpreter and the legacy API. In the code, we add `_PyInterpreterConfig.allow_exec` and `_PyInterpreterConfig.allow_daemon_threads`. We also add `Py_RTFLAGS_DAEMON_THREADS` and `Py_RTFLAGS_EXEC`.
This commit is contained in:
parent
3b86538661
commit
4702552885
15 changed files with 220 additions and 47 deletions
|
@ -5773,6 +5773,13 @@ os_execv_impl(PyObject *module, path_t *path, PyObject *argv)
|
|||
EXECV_CHAR **argvlist;
|
||||
Py_ssize_t argc;
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (!_PyInterpreterState_HasFeature(interp, Py_RTFLAGS_EXEC)) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"exec not supported for isolated subinterpreters");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* execv has two arguments: (path, argv), where
|
||||
argv is a list or tuple of strings. */
|
||||
|
||||
|
@ -5839,6 +5846,13 @@ os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env)
|
|||
EXECV_CHAR **envlist;
|
||||
Py_ssize_t argc, envc;
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (!_PyInterpreterState_HasFeature(interp, Py_RTFLAGS_EXEC)) {
|
||||
PyErr_SetString(PyExc_RuntimeError,
|
||||
"exec not supported for isolated subinterpreters");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* execve has three arguments: (path, argv, env), where
|
||||
argv is a list or tuple of strings and env is a dictionary
|
||||
like posix.environ. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue