File tree 1 file changed +15
-7
lines changed
1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -143,10 +143,19 @@ def _finish_handle(self):
143
143
"""Finish handle, if anything should be done when it's all wrapped up."""
144
144
pass
145
145
146
- def __enter__ (self ):
147
- # flush anything out before starting
146
+ def _flush (self ):
147
+ """flush sys.stdout/err and low-level FDs"""
148
+ if self ._stdout and sys .stdout :
149
+ sys .stdout .flush ()
150
+ if self ._stderr and sys .stderr :
151
+ sys .stderr .flush ()
152
+
148
153
libc .fflush (c_stdout_p )
149
154
libc .fflush (c_stderr_p )
155
+
156
+ def __enter__ (self ):
157
+ # flush anything out before starting
158
+ self ._flush ()
150
159
# setup handle
151
160
self ._setup_handle ()
152
161
self ._control_r , self ._control_w = os .pipe ()
@@ -172,8 +181,7 @@ def flush_main():
172
181
msg = flush_queue .get ()
173
182
if msg == 'stop' :
174
183
return
175
- libc .fflush (c_stdout_p )
176
- libc .fflush (c_stderr_p )
184
+ self ._flush ()
177
185
178
186
flush_thread = threading .Thread (target = flush_main )
179
187
flush_thread .daemon = True
@@ -241,9 +249,9 @@ def forwarder():
241
249
return self .handle
242
250
243
251
def __exit__ (self , exc_type , exc_value , traceback ):
244
- # flush the underlying C buffers
245
- libc . fflush ( c_stdout_p )
246
- libc . fflush ( c_stderr_p )
252
+ # flush before exiting
253
+ self . _flush ( )
254
+
247
255
# signal output is complete on control pipe
248
256
os .write (self ._control_w , b'\1 ' )
249
257
self .thread .join ()
You can’t perform that action at this time.
0 commit comments