diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-07-31 15:50:13 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-07-31 15:50:13 (GMT) |
commit | a7a4c41411026f5c049bb147425f6ce34c187bb6 (patch) | |
tree | a7151fa9576f3fd42425fbd3910f9d0fa0337914 /Lib | |
parent | b20ac4df842380e48e4db1830c7c14fab34f6435 (diff) | |
parent | 6fb1e740c67d8940fe27883d77f0dc46431aa9b4 (diff) | |
download | cpython-a7a4c41411026f5c049bb147425f6ce34c187bb6.zip cpython-a7a4c41411026f5c049bb147425f6ce34c187bb6.tar.gz cpython-a7a4c41411026f5c049bb147425f6ce34c187bb6.tar.bz2 |
Merge 3.4 (asyncio)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/base_subprocess.py | 9 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_subprocess.py | 15 |
2 files changed, 22 insertions, 2 deletions
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py index c1477b8..a6971b1 100644 --- a/Lib/asyncio/base_subprocess.py +++ b/Lib/asyncio/base_subprocess.py @@ -35,8 +35,13 @@ class BaseSubprocessTransport(transports.SubprocessTransport): self._pipes[2] = None # Create the child process: set the _proc attribute - self._start(args=args, shell=shell, stdin=stdin, stdout=stdout, - stderr=stderr, bufsize=bufsize, **kwargs) + try: + self._start(args=args, shell=shell, stdin=stdin, stdout=stdout, + stderr=stderr, bufsize=bufsize, **kwargs) + except: + self.close() + raise + self._pid = self._proc.pid self._extra['subprocess'] = self._proc diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index ea85e19..d138c26 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -1,6 +1,7 @@ import signal import sys import unittest +import warnings from unittest import mock import asyncio @@ -413,6 +414,20 @@ class SubprocessMixin: # the transport was not notified yet self.assertFalse(killed) + def test_popen_error(self): + # Issue #24763: check that the subprocess transport is closed + # when BaseSubprocessTransport fails + with mock.patch('subprocess.Popen') as popen: + exc = ZeroDivisionError + popen.side_effect = exc + + create = asyncio.create_subprocess_exec(sys.executable, '-c', + 'pass', loop=self.loop) + with warnings.catch_warnings(record=True) as warns: + with self.assertRaises(exc): + self.loop.run_until_complete(create) + self.assertEqual(warns, []) + if sys.platform != 'win32': # Unix |