File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222 import resource
2323except ImportError :
2424 resource = None
25+ try :
26+ import threading
27+ except ImportError :
28+ threading = None
2529
2630mswindows = (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
You can’t perform that action at this time.
0 commit comments