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
@@ -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
You can’t perform that action at this time.
0 commit comments