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

Skip to content

Commit 267964c

Browse files
committed
Forward port new tests from Issue #18851.
2 parents 79a53ea + a839271 commit 267964c

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lib/test/test_subprocess.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
import resource
2323
except ImportError:
2424
resource = None
25+
try:
26+
import threading
27+
except ImportError:
28+
threading = None
2529

2630
mswindows = (sys.platform == "win32")
2731

@@ -1020,6 +1024,36 @@ def test_leaking_fds_on_error(self):
10201024
if c.exception.errno not in (errno.ENOENT, errno.EACCES):
10211025
raise c.exception
10221026

1027+
@unittest.skipIf(threading is None, "threading required")
1028+
def test_double_close_on_error(self):
1029+
# Issue #18851
1030+
fds = []
1031+
def open_fds():
1032+
for i in range(20):
1033+
fds.extend(os.pipe())
1034+
time.sleep(0.001)
1035+
t = threading.Thread(target=open_fds)
1036+
t.start()
1037+
try:
1038+
with self.assertRaises(EnvironmentError):
1039+
subprocess.Popen(['nonexisting_i_hope'],
1040+
stdin=subprocess.PIPE,
1041+
stdout=subprocess.PIPE,
1042+
stderr=subprocess.PIPE)
1043+
finally:
1044+
t.join()
1045+
exc = None
1046+
for fd in fds:
1047+
# If a double close occurred, some of those fds will
1048+
# already have been closed by mistake, and os.close()
1049+
# here will raise.
1050+
try:
1051+
os.close(fd)
1052+
except OSError as e:
1053+
exc = e
1054+
if exc is not None:
1055+
raise exc
1056+
10231057
def test_issue8780(self):
10241058
# Ensure that stdout is inherited from the parent
10251059
# if stdout=PIPE is not used

0 commit comments

Comments
 (0)