Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 361e30c

Browse files
committed
Undo supposed fix for Issue #15798 until I understand why this is
causing test_multiprocessing_forkserver and test_multiprocessing_spawn failures on head (3.4).
1 parent 1eda9e7 commit 361e30c

4 files changed

Lines changed: 6 additions & 29 deletions

File tree

Lib/subprocess.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,10 +1368,7 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
13681368
executable_list = tuple(
13691369
os.path.join(os.fsencode(dir), executable)
13701370
for dir in os.get_exec_path(env))
1371-
# Never close stdin, stdout and stderr for the child.
1372-
fds_to_keep = {0,1,2}
1373-
fds_to_keep.update(pass_fds)
1374-
# Our child uses this one to signal error before exec().
1371+
fds_to_keep = set(pass_fds)
13751372
fds_to_keep.add(errpipe_write)
13761373
self.pid = _posixsubprocess.fork_exec(
13771374
args, executable_list,

Lib/test/test_subprocess.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,27 +1559,6 @@ def test_close_fds_0_1_2(self):
15591559
# all standard fds closed.
15601560
self.check_close_std_fds([0, 1, 2])
15611561

1562-
def test_small_errpipe_write_fd(self):
1563-
"""Issue #15798: Popen should work when stdio fds are available."""
1564-
new_stdin = os.dup(0)
1565-
new_stdout = os.dup(1)
1566-
try:
1567-
os.close(0)
1568-
os.close(1)
1569-
1570-
# Side test: if errpipe_write fails to have its CLOEXEC
1571-
# flag set this should cause the parent to think the exec
1572-
# failed. Extremely unlikely: everyone supports CLOEXEC.
1573-
subprocess.Popen([
1574-
sys.executable, "-c",
1575-
"print('AssertionError:0:CLOEXEC failure.')"]).wait()
1576-
finally:
1577-
# Restore original stdin and stdout
1578-
os.dup2(new_stdin, 0)
1579-
os.dup2(new_stdout, 1)
1580-
os.close(new_stdin)
1581-
os.close(new_stdout)
1582-
15831562
def test_remapping_std_fds(self):
15841563
# open up some temporary files
15851564
temps = [mkstemp() for i in range(3)]

Misc/NEWS

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ Core and Builtins
1818
Library
1919
-------
2020

21-
- Issue #15798: Fixed subprocess.Popen() to no longer fail if file
22-
descriptor 0, 1 or 2 is closed.
23-
2421
- Issue #19088: Fixed incorrect caching of the copyreg module in
2522
object.__reduce__() and object.__reduce_ex__().
2623

Modules/_posixsubprocess.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ child_exec(char *const exec_array[],
449449
local_max_fd = max_fd;
450450
#endif
451451
/* TODO HP-UX could use pstat_getproc() if anyone cares about it. */
452-
_close_open_fd_range(0, local_max_fd, py_fds_to_keep);
452+
_close_open_fd_range(3, local_max_fd, py_fds_to_keep);
453453
}
454454

455455
/* This loop matches the Lib/os.py _execvpe()'s PATH search when */
@@ -526,6 +526,10 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
526526
&restore_signals, &call_setsid, &preexec_fn))
527527
return NULL;
528528

529+
if (close_fds && errpipe_write < 3) { /* precondition */
530+
PyErr_SetString(PyExc_ValueError, "errpipe_write must be >= 3");
531+
return NULL;
532+
}
529533
if (PySequence_Length(py_fds_to_keep) < 0) {
530534
PyErr_SetString(PyExc_ValueError, "cannot get length of fds_to_keep");
531535
return NULL;

0 commit comments

Comments
 (0)