Skip to content

Commit 0d4ccdd

Browse files
Do not restrict subprocess.
1 parent b1402e3 commit 0d4ccdd

File tree

8 files changed

+12
-45
lines changed

8 files changed

+12
-45
lines changed

Include/cpython/initconfig.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,12 @@ PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
245245

246246
typedef struct {
247247
int allow_fork;
248-
int allow_subprocess;
249248
int allow_threads;
250249
} _PyInterpreterConfig;
251250

252251
#define _PyInterpreterConfig_LEGACY_INIT \
253252
{ \
254253
.allow_fork = 1, \
255-
.allow_subprocess = 1, \
256254
.allow_threads = 1, \
257255
}
258256

Include/cpython/pystate.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@ is available in a given context. For example, forking the process
1111
might not be allowed in the current interpreter (i.e. os.fork() would fail).
1212
*/
1313

14-
// We leave the first 10 for less-specific features.
15-
1614
/* Set if threads are allowed. */
17-
#define Py_RTFLAGS_THREADS (1UL << 10)
15+
#define Py_RTFLAGS_THREADS (1UL << 10)
1816

1917
/* Set if os.fork() is allowed. */
20-
#define Py_RTFLAGS_FORK (1UL << 15)
21-
22-
/* Set if subprocesses are allowed. */
23-
#define Py_RTFLAGS_SUBPROCESS (1UL << 16)
18+
#define Py_RTFLAGS_FORK (1UL << 15)
2419

2520

2621
PyAPI_FUNC(int) _PyInterpreterState_HasFeature(PyInterpreterState *interp,

Lib/test/test_capi.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,14 +1094,13 @@ def test_configured_settings(self):
10941094

10951095
THREADS = 1<<10
10961096
FORK = 1<<15
1097-
SUBPROCESS = 1<<16
10981097

10991098
for config, expected in {
1100-
(True, True, True): THREADS | FORK | SUBPROCESS,
1101-
(False, False, False): 0,
1102-
(False, True, True): THREADS | SUBPROCESS,
1099+
(True, True): THREADS | FORK,
1100+
(False, False): 0,
1101+
(False, True): THREADS,
11031102
}.items():
1104-
allow_fork, allow_subprocess, allow_threads = config
1103+
allow_fork, allow_threads = config
11051104
expected = {
11061105
'feature_flags': expected,
11071106
}
@@ -1116,7 +1115,6 @@ def test_configured_settings(self):
11161115
json.dump(settings, stdin)
11171116
'''),
11181117
allow_fork=allow_fork,
1119-
allow_subprocess=allow_subprocess,
11201118
allow_threads=allow_threads,
11211119
)
11221120
out = stdout.read()

Lib/test/test_embed.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,10 +1650,9 @@ def test_init_use_frozen_modules(self):
16501650
def test_init_main_interpreter_settings(self):
16511651
THREADS = 1<<10
16521652
FORK = 1<<15
1653-
SUBPROCESS = 1<<16
16541653
expected = {
16551654
# All optional features should be enabled.
1656-
'feature_flags': THREADS | FORK | SUBPROCESS,
1655+
'feature_flags': THREADS | FORK,
16571656
}
16581657
out, err = self.run_embedded_interpreter(
16591658
'test_init_main_interpreter_settings',

Modules/_posixsubprocess.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,8 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
825825
&preexec_fn, &allow_vfork))
826826
return NULL;
827827

828-
if ((preexec_fn != Py_None) &&
829-
(PyInterpreterState_Get() != PyInterpreterState_Main())) {
828+
PyInterpreterState *interp = PyInterpreterState_Get();
829+
if ((preexec_fn != Py_None) && (interp != PyInterpreterState_Main())) {
830830
PyErr_SetString(PyExc_RuntimeError,
831831
"preexec_fn not supported within subinterpreters");
832832
return NULL;
@@ -841,13 +841,6 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
841841
return NULL;
842842
}
843843

844-
PyInterpreterState *interp = PyInterpreterState_Get();
845-
if (!_PyInterpreterState_HasFeature(interp, Py_RTFLAGS_SUBPROCESS)) {
846-
PyErr_SetString(PyExc_RuntimeError,
847-
"subprocess not supported for isolated subinterpreters");
848-
return NULL;
849-
}
850-
851844
/* We need to call gc.disable() when we'll be calling preexec_fn */
852845
if (preexec_fn != Py_None) {
853846
need_to_reenable_gc = PyGC_Disable();

Modules/_testcapimodule.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,29 +3231,24 @@ run_in_subinterp_with_config(PyObject *self, PyObject *args, PyObject *kwargs)
32313231
{
32323232
const char *code;
32333233
int allow_fork = -1;
3234-
int allow_subprocess = -1;
32353234
int allow_threads = -1;
32363235
int r;
32373236
PyThreadState *substate, *mainstate;
32383237
/* only initialise 'cflags.cf_flags' to test backwards compatibility */
32393238
PyCompilerFlags cflags = {0};
32403239

32413240
static char *kwlist[] = {"code",
3242-
"allow_fork", "allow_subprocess", "allow_threads",
3241+
"allow_fork", "allow_threads",
32433242
NULL};
32443243
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
3245-
"s$ppp:run_in_subinterp_with_config", kwlist,
3246-
&code, &allow_fork, &allow_subprocess, &allow_threads)) {
3244+
"s$pp:run_in_subinterp_with_config", kwlist,
3245+
&code, &allow_fork, &allow_threads)) {
32473246
return NULL;
32483247
}
32493248
if (allow_fork < 0) {
32503249
PyErr_SetString(PyExc_ValueError, "missing allow_fork");
32513250
return NULL;
32523251
}
3253-
if (allow_subprocess < 0) {
3254-
PyErr_SetString(PyExc_ValueError, "missing allow_subprocess");
3255-
return NULL;
3256-
}
32573252
if (allow_threads < 0) {
32583253
PyErr_SetString(PyExc_ValueError, "missing allow_threads");
32593254
return NULL;
@@ -3265,7 +3260,6 @@ run_in_subinterp_with_config(PyObject *self, PyObject *args, PyObject *kwargs)
32653260

32663261
_PyInterpreterConfig config = {
32673262
.allow_fork = allow_fork,
3268-
.allow_subprocess = allow_subprocess,
32693263
.allow_threads = allow_threads,
32703264
};
32713265
substate = _Py_NewInterpreterFromConfig(&config);

Modules/_winapi.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,13 +1089,6 @@ _winapi_CreateProcess_impl(PyObject *module,
10891089
return NULL;
10901090
}
10911091

1092-
PyInterpreterState *interp = PyInterpreterState_Get();
1093-
if (!_PyInterpreterState_HasFeature(interp, Py_RTFLAGS_SUBPROCESS)) {
1094-
PyErr_SetString(PyExc_RuntimeError,
1095-
"subprocess not supported for isolated subinterpreters");
1096-
return NULL;
1097-
}
1098-
10991092
ZeroMemory(&si, sizeof(si));
11001093
si.StartupInfo.cb = sizeof(si);
11011094

Python/pylifecycle.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,6 @@ init_interp_settings(PyInterpreterState *interp, const _PyInterpreterConfig *con
618618
if (config->allow_fork) {
619619
interp->feature_flags |= Py_RTFLAGS_FORK;
620620
}
621-
if (config->allow_subprocess) {
622-
interp->feature_flags |= Py_RTFLAGS_SUBPROCESS;
623-
}
624621
if (config->allow_threads) {
625622
interp->feature_flags |= Py_RTFLAGS_THREADS;
626623
}

0 commit comments

Comments
 (0)