@@ -284,6 +284,9 @@ def __enter__(self):
284284 # OS-level pipe for redirecting output to logger
285285 self .read_fd , self .write_fd = os .pipe ()
286286
287+ os .set_inheritable (self .read_fd , True )
288+ os .set_inheritable (self .write_fd , True )
289+
287290 # Multiprocessing pipe for communication back from the daemon
288291 # Currently only used to save echo value between uses
289292 self .parent , self .child = multiprocessing .Pipe ()
@@ -292,19 +295,19 @@ def __enter__(self):
292295 try :
293296 # need to pass this b/c multiprocessing closes stdin in child.
294297 try :
295- input_stream = os .fdopen ( os . dup (sys .stdin .fileno () ))
298+ input_fd = os .dup (sys .stdin .fileno ())
296299 except BaseException :
297- input_stream = None # just don't forward input if this fails
300+ input_fd = None # just don't forward input if this fails
298301
299302 self .process = multiprocessing .Process (
300- target = self ._writer_daemon , args = (input_stream ,))
303+ target = self ._writer_daemon , args = (input_fd ,))
301304 self .process .daemon = True # must set before start()
302305 self .process .start ()
303306 os .close (self .read_fd ) # close in the parent process
304307
305308 finally :
306- if input_stream :
307- input_stream .close ()
309+ if input_fd :
310+ os .close (input_fd )
308311
309312 # Flush immediately before redirecting so that anything buffered
310313 # goes to the original stream
@@ -412,12 +415,13 @@ def force_echo(self):
412415 sys .stdout .write (xoff )
413416 sys .stdout .flush ()
414417
415- def _writer_daemon (self , stdin ):
418+ def _writer_daemon (self , input_fd ):
416419 """Daemon that writes output to the log file and stdout."""
417420 # Use line buffering (3rd param = 1) since Python 3 has a bug
418421 # that prevents unbuffered text I/O.
419422 in_pipe = os .fdopen (self .read_fd , 'r' , 1 )
420423 os .close (self .write_fd )
424+ stdin = os .fdopen (input_fd )
421425
422426 echo = self .echo # initial echo setting, user-controllable
423427 force_echo = False # parent can force echo for certain output
0 commit comments