@@ -40,7 +40,7 @@ def read(socket, n=4096):
40
40
poll .poll ()
41
41
42
42
try :
43
- if hasattr (socket , ' recv' ):
43
+ if hasattr (socket , " recv" ):
44
44
return socket .recv (n )
45
45
if isinstance (socket , pysocket .SocketIO ):
46
46
return socket .read (n )
@@ -49,13 +49,15 @@ def read(socket, n=4096):
49
49
if e .errno not in recoverable_errors :
50
50
raise
51
51
except Exception as e :
52
- is_pipe_ended = (isinstance (socket , NpipeSocket ) and
53
- len (e .args ) > 0 and
54
- e .args [0 ] == NPIPE_ENDED )
52
+ is_pipe_ended = (
53
+ isinstance (socket , NpipeSocket )
54
+ and len (e .args ) > 0
55
+ and e .args [0 ] == NPIPE_ENDED
56
+ )
55
57
if is_pipe_ended :
56
58
# npipes don't support duplex sockets, so we interpret
57
59
# a PIPE_ENDED error as a close operation (0-length read).
58
- return ''
60
+ return ""
59
61
raise
60
62
61
63
@@ -85,7 +87,7 @@ def next_frame_header(socket):
85
87
except SocketError :
86
88
return (- 1 , - 1 )
87
89
88
- stream , actual = struct .unpack (' >BxxxL' , data )
90
+ stream , actual = struct .unpack (" >BxxxL" , data )
89
91
return (stream , actual )
90
92
91
93
@@ -156,22 +158,18 @@ def consume_socket_output(frames, demux=False):
156
158
157
159
# If the streams are demultiplexed, the generator yields tuples
158
160
# (stdout, stderr)
159
- out = [None , None ]
160
- for frame in frames :
161
+ stdout = []
162
+ stderr = []
163
+ for stdout_frame , stderr_frame in frames :
161
164
# It is guaranteed that for each frame, one and only one stream
162
165
# is not None.
163
- assert frame != (None , None )
164
- if frame [0 ] is not None :
165
- if out [0 ] is None :
166
- out [0 ] = frame [0 ]
167
- else :
168
- out [0 ] += frame [0 ]
166
+ if stdout_frame :
167
+ stdout .append (stdout_frame )
169
168
else :
170
- if out [1 ] is None :
171
- out [1 ] = frame [1 ]
172
- else :
173
- out [1 ] += frame [1 ]
174
- return tuple (out )
169
+ stderr .append (stderr_frame )
170
+ stdout = b"" .join (stdout ) if len (stdout ) > 0 else None
171
+ stderr = b"" .join (stderr ) if len (stderr ) > 0 else None
172
+ return stdout , stderr
175
173
176
174
177
175
def demux_adaptor (stream_id , data ):
0 commit comments