8000 Refactoring: get rid of _try_connected(). · python/asyncio@34acced · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Commit 34acced

Browse files
committed
Refactoring: get rid of _try_connected().
1 parent 0e313f4 commit 34acced

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

asyncio/base_subprocess.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,34 @@ def _post_init(self):
7575
proc = self._proc
7676
loop = self._loop
7777
if proc.stdin is not None:
78-
transp, proto = yield from loop.connect_write_pipe(
78+
_, pipe = yield from loop.connect_write_pipe(
7979
lambda: WriteSubprocessPipeProto(self, STDIN),
8080
proc.stdin)
81+
self._pipes[STDIN] = pipe
8182
if proc.stdout is not None:
82-
transp, proto = yield from loop.connect_read_pipe(
83+
_, pipe = yield from loop.connect_read_pipe(
8384
lambda: ReadSubprocessPipeProto(self, STDOUT),
8485
proc.stdout)
86+
self._pipes[STDOUT] = pipe
8587
if proc.stderr is not None:
86-
transp, proto = yield from loop.connect_read_pipe(
88+
_, pipe = yield from loop.connect_read_pipe(
8789
lambda: ReadSubprocessPipeProto(self, STDERR),
8890
proc.stderr)
89-
if not self._pipes:
90-
self._try_connected()
91+
self._pipes[STDERR] = pipe
92+
93+
assert self._pending_calls is not None
94+
95+
self._loop.call_soon(self._protocol.connection_made, self)
96+
for callback, data in self._pending_calls:
97+
self._loop.call_soon(callback, *data)
98+
self._pending_calls = None
9199

92100
def _call(self, cb, *data):
93101
if self._pending_calls is not None:
94102
self._pending_calls.append((cb, data))
95103
else:
96104
self._loop.call_soon(cb, *data)
97105

98-
def _try_connected(self):
99-
assert self._pending_calls is not None
100-
if all(p is not None and p.connected for p in self._pipes.values()):
101-
self._loop.call_soon(self._protocol.connection_made, self)
102-
for callback, data in self._pending_calls:
103-
self._loop.call_soon(callback, *data)
104-
self._pending_calls = None
105-
106106
def _pipe_connection_lost(self, fd, exc):
107107
self._call(self._protocol.pipe_connection_lost, fd, exc)
108108
self._try_finish()
@@ -136,19 +136,15 @@ def _call_connection_lost(self, exc):
136136

137137

138138
class WriteSubprocessPipeProto(protocols.BaseProtocol):
139-
pipe = None
140139

141140
def __init__(self, proc, fd):
142141
self.proc = proc
143142
self.fd = fd
144-
self.connected = False
143+
self.pipe = None
145144
self.disconnected = False
146-
proc._pipes[fd] = self
147145

148146
def connection_made(self, transport):
149-
self.connected = True
150147
self.pipe = transport
151-
self.proc._try_connected()
152148

153149
def connection_lost(self, exc):
154150
self.disconnected = True

0 commit comments

Comments
 (0)
0