@@ -75,34 +75,34 @@ def _post_init(self):
75
75
proc = self ._proc
76
76
loop = self ._loop
77
77
if proc .stdin is not None :
78
- transp , proto = yield from loop .connect_write_pipe (
78
+ _ , pipe = yield from loop .connect_write_pipe (
79
79
lambda : WriteSubprocessPipeProto (self , STDIN ),
80
80
proc .stdin )
81
+ self ._pipes [STDIN ] = pipe
81
82
if proc .stdout is not None :
82
- transp , proto = yield from loop .connect_read_pipe (
83
+ _ , pipe = yield from loop .connect_read_pipe (
83
84
lambda : ReadSubprocessPipeProto (self , STDOUT ),
84
85
proc .stdout )
86
+ self ._pipes [STDOUT ] = pipe
85
87
if proc .stderr is not None :
86
- transp , proto = yield from loop .connect_read_pipe (
88
+ _ , pipe = yield from loop .connect_read_pipe (
87
89
lambda : ReadSubprocessPipeProto (self , STDERR ),
88
90
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
91
99
92
100
def _call (self , cb , * data ):
93
101
if self ._pending_calls is not None :
94
102
self ._pending_calls .append ((cb , data ))
95
103
else :
96
104
self ._loop .call_soon (cb , * data )
97
105
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
-
106
106
def _pipe_connection_lost (self , fd , exc ):
107
107
self ._call (self ._protocol .pipe_connection_lost , fd , exc )
108
108
self ._try_finish ()
@@ -136,19 +136,15 @@ def _call_connection_lost(self, exc):
136
136
137
137
138
138
class WriteSubprocessPipeProto (protocols .BaseProtocol ):
139
- pipe = None
140
139
141
140
def __init__ (self , proc , fd ):
142
141
self .proc = proc
143
142
self .fd = fd
144
- self .connected = False
143
+ self .pipe = None
145
144
self .disconnected = False
146
- proc ._pipes [fd ] = self
147
145
148
146
def connection_made (self , transport ):
149
- self .connected = True
150
147
self .pipe = transport
151
- self .proc ._try_connected ()
152
148
153
149
def connection_lost (self , exc ):
154
150
self .disconnected = True
0 commit comments