Fix fallback to devnull when trying to preserve stdin in worker (#74192)
ci_complete
This commit is contained in:
parent
ee38202fc0
commit
3cbe16fa7a
1 changed files with 9 additions and 8 deletions
|
@ -72,25 +72,27 @@ class WorkerProcess(multiprocessing_context.Process):
|
|||
self._loader._tempfiles = set()
|
||||
|
||||
def _save_stdin(self):
|
||||
self._new_stdin = os.devnull
|
||||
self._new_stdin = None
|
||||
try:
|
||||
if sys.stdin.isatty() and sys.stdin.fileno() is not None:
|
||||
try:
|
||||
self._new_stdin = os.fdopen(os.dup(sys.stdin.fileno()))
|
||||
except OSError:
|
||||
# couldn't dupe stdin, most likely because it's
|
||||
# not a valid file descriptor, so we just rely on
|
||||
# using the one that was passed in
|
||||
# not a valid file descriptor
|
||||
pass
|
||||
except (AttributeError, ValueError):
|
||||
# couldn't get stdin's fileno, so we just carry on
|
||||
# couldn't get stdin's fileno
|
||||
pass
|
||||
|
||||
if self._new_stdin is None:
|
||||
self._new_stdin = open(os.devnull)
|
||||
|
||||
def start(self):
|
||||
'''
|
||||
multiprocessing.Process replaces the worker's stdin with a new file
|
||||
opened on os.devnull, but we wish to preserve it if it is connected to
|
||||
a terminal. Therefore dup a copy prior to calling the real start(),
|
||||
but we wish to preserve it if it is connected to a terminal.
|
||||
Therefore dup a copy prior to calling the real start(),
|
||||
ensuring the descriptor is preserved somewhere in the new child, and
|
||||
make sure it is closed in the parent when start() completes.
|
||||
'''
|
||||
|
@ -99,8 +101,7 @@ class WorkerProcess(multiprocessing_context.Process):
|
|||
try:
|
||||
return super(WorkerProcess, self).start()
|
||||
finally:
|
||||
if self._new_stdin != os.devnull:
|
||||
self._new_stdin.close()
|
||||
self._new_stdin.close()
|
||||
|
||||
def _hard_exit(self, e):
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue