tolerate 'batch' systems that mess with stdin (#23596)
* tolerate 'batch' systems taht mess with stdin fixes #23541 * have pause on windows tolerate devnull * tuplie
This commit is contained in:
parent
1ef2b6b302
commit
586fcae398
2 changed files with 22 additions and 17 deletions
|
@ -68,21 +68,25 @@ class WorkerProcess(multiprocessing.Process):
|
||||||
self._variable_manager = variable_manager
|
self._variable_manager = variable_manager
|
||||||
self._shared_loader_obj = shared_loader_obj
|
self._shared_loader_obj = shared_loader_obj
|
||||||
|
|
||||||
# dupe stdin, if we have one
|
if sys.stdin.isatty():
|
||||||
self._new_stdin = sys.stdin
|
# dupe stdin, if we have one
|
||||||
try:
|
self._new_stdin = sys.stdin
|
||||||
fileno = sys.stdin.fileno()
|
try:
|
||||||
if fileno is not None:
|
fileno = sys.stdin.fileno()
|
||||||
try:
|
if fileno is not None:
|
||||||
self._new_stdin = os.fdopen(os.dup(fileno))
|
try:
|
||||||
except OSError:
|
self._new_stdin = os.fdopen(os.dup(fileno))
|
||||||
# couldn't dupe stdin, most likely because it's
|
except OSError:
|
||||||
# not a valid file descriptor, so we just rely on
|
# couldn't dupe stdin, most likely because it's
|
||||||
# using the one that was passed in
|
# not a valid file descriptor, so we just rely on
|
||||||
pass
|
# using the one that was passed in
|
||||||
except (AttributeError, ValueError):
|
pass
|
||||||
# couldn't get stdin's fileno, so we just carry on
|
except (AttributeError, ValueError):
|
||||||
pass
|
# couldn't get stdin's fileno, so we just carry on
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# set to /dev/null
|
||||||
|
self._new_stdin = os.devnull
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -125,8 +125,9 @@ class ActionModule(ActionBase):
|
||||||
fd = None
|
fd = None
|
||||||
try:
|
try:
|
||||||
fd = self._connection._new_stdin.fileno()
|
fd = self._connection._new_stdin.fileno()
|
||||||
except ValueError:
|
except (ValueError, AttributeError):
|
||||||
# someone is using a closed file descriptor as stdin
|
# ValueError: someone is using a closed file descriptor as stdin
|
||||||
|
# AttributeError: someone is using a null file descriptor as stdin on windoez
|
||||||
pass
|
pass
|
||||||
if fd is not None:
|
if fd is not None:
|
||||||
if isatty(fd):
|
if isatty(fd):
|
||||||
|
|
Loading…
Reference in a new issue