diff -r 9e3be159d023 Lib/asyncio/base_subprocess.py --- a/Lib/asyncio/base_subprocess.py Fri Jul 31 07:58:56 2015 -0700 +++ b/Lib/asyncio/base_subprocess.py Fri Jul 31 17:30:29 2015 +0200 @@ -34,6 +34,15 @@ class BaseSubprocessTransport(transports if stderr == subprocess.PIPE: self._pipes[2] = None + try: + self._init(args, shell, stdin, stdout, stderr, bufsize, + waiter, kwargs) + except: + self.close() + raise + + def _init(self, args, shell, stdin, stdout, stderr, bufsize, + waiter, kwargs): # Create the child process: set the _proc attribute self._start(args=args, shell=shell, stdin=stdin, stdout=stdout, stderr=stderr, bufsize=bufsize, **kwargs) diff -r 9e3be159d023 Lib/test/test_asyncio/test_subprocess.py --- a/Lib/test/test_asyncio/test_subprocess.py Fri Jul 31 07:58:56 2015 -0700 +++ b/Lib/test/test_asyncio/test_subprocess.py Fri Jul 31 17:30:29 2015 +0200 @@ -1,6 +1,7 @@ import signal import sys import unittest +import warnings from unittest import mock import asyncio @@ -413,6 +414,25 @@ class SubprocessMixin: # the transport was not notified yet self.assertFalse(killed) + def test_popen_error(self): + @asyncio.coroutine + def popen_bug(): + args = [sys.executable, '-c', 'pass'] + proc = yield from asyncio.create_subprocess_exec( + *args, + loop=self.loop) + + + with mock.patch('subprocess.Popen') as popen: + coro = popen_bug() + + exc = ZeroDivisionError + popen.side_effect = exc + with warnings.catch_warnings(record=True) as warns: + with self.assertRaises(exc): + self.loop.run_until_complete(coro) + self.assertEqual(warns, []) + if sys.platform != 'win32': # Unix