Skip to content

Commit 0d4efba

Browse files
gpsheadcptpcrd
authored andcommitted
Move err_close_fds adds next to pipe creation.
1 parent 783e6f8 commit 0d4efba

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Lib/subprocess.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,8 @@ def _get_handles(self, stdin, stdout, stderr):
13491349
if p2cread is None:
13501350
p2cread, _ = _winapi.CreatePipe(None, 0)
13511351
p2cread = Handle(p2cread)
1352-
_winapi.CloseHandle(_)
13531352
err_close_fds.append(p2cread)
1353+
_winapi.CloseHandle(_)
13541354
elif stdin == PIPE:
13551355
p2cread, p2cwrite = _winapi.CreatePipe(None, 0)
13561356
p2cread, p2cwrite = Handle(p2cread), Handle(p2cwrite)
@@ -1369,8 +1369,8 @@ def _get_handles(self, stdin, stdout, stderr):
13691369
if c2pwrite is None:
13701370
_, c2pwrite = _winapi.CreatePipe(None, 0)
13711371
c2pwrite = Handle(c2pwrite)
1372-
_winapi.CloseHandle(_)
13731372
err_close_fds.append(c2pwrite)
1373+
_winapi.CloseHandle(_)
13741374
elif stdout == PIPE:
13751375
c2pread, c2pwrite = _winapi.CreatePipe(None, 0)
13761376
c2pread, c2pwrite = Handle(c2pread), Handle(c2pwrite)
@@ -1389,8 +1389,8 @@ def _get_handles(self, stdin, stdout, stderr):
13891389
if errwrite is None:
13901390
_, errwrite = _winapi.CreatePipe(None, 0)
13911391
errwrite = Handle(errwrite)
1392-
_winapi.CloseHandle(_)
13931392
err_close_fds.append(errwrite)
1393+
_winapi.CloseHandle(_)
13941394
elif stderr == PIPE:
13951395
errread, errwrite = _winapi.CreatePipe(None, 0)
13961396
errread, errwrite = Handle(errread), Handle(errwrite)
@@ -1696,9 +1696,9 @@ def _get_handles(self, stdin, stdout, stderr):
16961696
pass
16971697
elif stdin == PIPE:
16981698
p2cread, p2cwrite = os.pipe()
1699+
err_close_fds.extend((p2cread, p2cwrite))
16991700
if self.pipesize > 0 and hasattr(fcntl, "F_SETPIPE_SZ"):
17001701
fcntl.fcntl(p2cwrite, fcntl.F_SETPIPE_SZ, self.pipesize)
1701-
err_close_fds.extend((p2cread, p2cwrite))
17021702
elif stdin == DEVNULL:
17031703
p2cread = self._get_devnull()
17041704
elif isinstance(stdin, int):
@@ -1711,9 +1711,9 @@ def _get_handles(self, stdin, stdout, stderr):
17111711
pass
17121712
elif stdout == PIPE:
17131713
c2pread, c2pwrite = os.pipe()
1714+
err_close_fds.extend((c2pread, c2pwrite))
17141715
if self.pipesize > 0 and hasattr(fcntl, "F_SETPIPE_SZ"):
17151716
fcntl.fcntl(c2pwrite, fcntl.F_SETPIPE_SZ, self.pipesize)
1716-
err_close_fds.extend((c2pread, c2pwrite))
17171717
elif stdout == DEVNULL:
17181718
c2pwrite = self._get_devnull()
17191719
elif isinstance(stdout, int):
@@ -1726,9 +1726,9 @@ def _get_handles(self, stdin, stdout, stderr):
17261726
pass
17271727
elif stderr == PIPE:
17281728
errread, errwrite = os.pipe()
1729+
err_close_fds.extend((errread, errwrite))
17291730
if self.pipesize > 0 and hasattr(fcntl, "F_SETPIPE_SZ"):
17301731
fcntl.fcntl(errwrite, fcntl.F_SETPIPE_SZ, self.pipesize)
1731-
err_close_fds.extend((errread, errwrite))
17321732
elif stderr == STDOUT:
17331733
if c2pwrite != -1:
17341734
errwrite = c2pwrite

0 commit comments

Comments
 (0)