diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-30 22:12:37 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-08-30 22:12:37 (GMT) |
commit | 267964c837bb7a1c60a7ce3cb8963a7cced7abb1 (patch) | |
tree | da8fa7489619a1a13a7abb06e5c8184525fd1989 | |
parent | 79a53ea7d7d66f515b6bd4a38b1adbe8961a69f2 (diff) | |
parent | a8392717f1ca5263fb0e942e7e64f9fdc8d115ef (diff) | |
download | cpython-267964c837bb7a1c60a7ce3cb8963a7cced7abb1.zip cpython-267964c837bb7a1c60a7ce3cb8963a7cced7abb1.tar.gz cpython-267964c837bb7a1c60a7ce3cb8963a7cced7abb1.tar.bz2 |
Forward port new tests from Issue #18851.
-rw-r--r-- | Lib/test/test_subprocess.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index b1c091e..94d72dc 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -22,6 +22,10 @@ try: import resource except ImportError: resource = None +try: + import threading +except ImportError: + threading = None mswindows = (sys.platform == "win32") @@ -1020,6 +1024,36 @@ class ProcessTestCase(BaseTestCase): if c.exception.errno not in (errno.ENOENT, errno.EACCES): raise c.exception + @unittest.skipIf(threading is None, "threading required") + def test_double_close_on_error(self): + # Issue #18851 + fds = [] + def open_fds(): + for i in range(20): + fds.extend(os.pipe()) + time.sleep(0.001) + t = threading.Thread(target=open_fds) + t.start() + try: + with self.assertRaises(EnvironmentError): + subprocess.Popen(['nonexisting_i_hope'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + finally: + t.join() + exc = None + for fd in fds: + # If a double close occurred, some of those fds will + # already have been closed by mistake, and os.close() + # here will raise. + try: + os.close(fd) + except OSError as e: + exc = e + if exc is not None: + raise exc + def test_issue8780(self): # Ensure that stdout is inherited from the parent # if stdout=PIPE is not used |