diff options
author | Seth M. Larson <SethMichaelLarson@users.noreply.github.com> | 2017-03-03 04:21:18 (GMT) |
---|---|---|
committer | Yury Selivanov <yselivanov@gmail.com> | 2017-03-03 04:21:18 (GMT) |
commit | 481cb70a724687d12553d38a749c16034af68a1e (patch) | |
tree | de7694fa41f50dca1b20e114030edf3cc6d11ae5 /Lib/asyncio | |
parent | 398ff91ac0b8f4d930cd5d9e3e6a4bf247f810ef (diff) | |
download | cpython-481cb70a724687d12553d38a749c16034af68a1e.zip cpython-481cb70a724687d12553d38a749c16034af68a1e.tar.gz cpython-481cb70a724687d12553d38a749c16034af68a1e.tar.bz2 |
bpo-29704: Fix asyncio.SubprocessStreamProtocol closing (#405)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/subprocess.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Lib/asyncio/subprocess.py b/Lib/asyncio/subprocess.py index b2f5304..06c7d4f 100644 --- a/Lib/asyncio/subprocess.py +++ b/Lib/asyncio/subprocess.py @@ -24,6 +24,8 @@ class SubprocessStreamProtocol(streams.FlowControlMixin, self._limit = limit self.stdin = self.stdout = self.stderr = None self._transport = None + self._process_exited = False + self._pipe_fds = [] def __repr__(self): info = [self.__class__.__name__] @@ -43,12 +45,14 @@ class SubprocessStreamProtocol(streams.FlowControlMixin, self.stdout = streams.StreamReader(limit=self._limit, loop=self._loop) self.stdout.set_transport(stdout_transport) + self._pipe_fds.append(1) stderr_transport = transport.get_pipe_transport(2) if stderr_transport is not None: self.stderr = streams.StreamReader(limit=self._limit, loop=self._loop) self.stderr.set_transport(stderr_transport) + self._pipe_fds.append(2) stdin_transport = transport.get_pipe_transport(0) if stdin_transport is not None: @@ -85,10 +89,19 @@ class SubprocessStreamProtocol(streams.FlowControlMixin, reader.feed_eof() else: reader.set_exception(exc) + + if fd in self._pipe_fds: + self._pipe_fds.remove(fd) + self._maybe_close_transport() def process_exited(self): - self._transport.close() - self._transport = None + self._process_exited = True + self._maybe_close_transport() + + def _maybe_close_transport(self): + if len(self._pipe_fds) == 0 and self._process_exited: + self._transport.close() + self._transport = None class Process: |