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

Skip to content

Commit a839271

Browse files
committed
Forward port new tests from Issue #18851.
1 parent 9939cc8 commit a839271

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

@@ -987,6 +991,36 @@ def test_leaking_fds_on_error(self):
987991
if c.exception.errno not in (errno.ENOENT, errno.EACCES):
988992
raise c.exception
989993

994+
@unittest.skipIf(threading is None, "threading required")
995+
def test_double_close_on_error(self):
996+
# Issue #18851
997+
fds = []
998+
def open_fds():
999+
for i in range(20):
1000+
fds.extend(os.pipe())
1001+
time.sleep(0.001)
1002+
t = threading.Thread(target=open_fds)
1003+
t.start()
1004+
try:
1005+
with self.assertRaises(EnvironmentError):
1006+
subprocess.Popen(['nonexisting_i_hope'],
1007+
stdin=subprocess.PIPE,
1008+
stdout=subprocess.PIPE,
1009+
stderr=subprocess.PIPE)
1010+
finally:
1011+
t.join()
1012+
exc = None
1013+
for fd in fds:
1014+
# If a double close occurred, some of those fds will
1015+
# already have been closed by mistake, and os.close()
1016+
# here will raise.
1017+
try:
1018+
os.close(fd)
1019+
except OSError as e:
1020+
exc = e
1021+
if exc is not None:
1022+
raise exc
1023+
9901024
def test_issue8780(self):
9911025
# Ensure that stdout is inherited from the parent
9921026
# if stdout=PIPE is not used

0 commit comments

Comments
 (0)