summaryrefslogtreecommitdiff
path: root/Lib/asyncio/base_subprocess.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-01-29 14:22:56 -0800
committerVictor Stinner <victor.stinner@gmail.com>2014-01-29 14:22:56 -0800
commite432c3e9705627e0520375ec85930aa3e5d658e6 (patch)
tree0522ab4eaf7506a0f17550d3e3b231f8421b1e8b /Lib/asyncio/base_subprocess.py
parent1758bd68008e825774bd5fb7b580171e1418bb7f (diff)
downloadcpython-e432c3e9705627e0520375ec85930aa3e5d658e6.tar.gz
asyncio: Get rid of _try_connected().
Diffstat (limited to 'Lib/asyncio/base_subprocess.py')
-rw-r--r--Lib/asyncio/base_subprocess.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py
index c5efda79b1..cc4f8cb759 100644
--- a/Lib/asyncio/base_subprocess.py
+++ b/Lib/asyncio/base_subprocess.py
@@ -75,19 +75,27 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
proc = self._proc
loop = self._loop
if proc.stdin is not None:
- transp, proto = yield from loop.connect_write_pipe(
+ _, pipe = yield from loop.connect_write_pipe(
lambda: WriteSubprocessPipeProto(self, STDIN),
proc.stdin)
+ self._pipes[STDIN] = pipe
if proc.stdout is not None:
- transp, proto = yield from loop.connect_read_pipe(
+ _, pipe = yield from loop.connect_read_pipe(
lambda: ReadSubprocessPipeProto(self, STDOUT),
proc.stdout)
+ self._pipes[STDOUT] = pipe
if proc.stderr is not None:
- transp, proto = yield from loop.connect_read_pipe(
+ _, pipe = yield from loop.connect_read_pipe(
lambda: ReadSubprocessPipeProto(self, STDERR),
proc.stderr)
- if not self._pipes:
- self._try_connected()
+ self._pipes[STDERR] = pipe
+
+ assert self._pending_calls is not None
+
+ self._loop.call_soon(self._protocol.connection_made, self)
+ for callback, data in self._pending_calls:
+ self._loop.call_soon(callback, *data)
+ self._pending_calls = None
def _call(self, cb, *data):
if self._pending_calls is not None:
@@ -95,14 +103,6 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
else:
self._loop.call_soon(cb, *data)
- def _try_connected(self):
- assert self._pending_calls is not None
- if all(p is not None and p.connected for p in self._pipes.values()):
- self._loop.call_soon(self._protocol.connection_made, self)
- for callback, data in self._pending_calls:
- self._loop.call_soon(callback, *data)
- self._pending_calls = None
-
def _pipe_connection_lost(self, fd, exc):
self._call(self._protocol.pipe_connection_lost, fd, exc)
self._try_finish()
@@ -136,19 +136,15 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
class WriteSubprocessPipeProto(protocols.BaseProtocol):
- pipe = None
def __init__(self, proc, fd):
self.proc = proc
self.fd = fd
- self.connected = False
+ self.pipe = None
self.disconnected = False
- proc._pipes[fd] = self
def connection_made(self, transport):
- self.connected = True
self.pipe = transport
- self.proc._try_connected()
def connection_lost(self, exc):
self.disconnected = True