Skip to content

Commit

Permalink
Avoid python3 error with no stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
mattaezell committed Mar 5, 2021
1 parent cdbb5ef commit 3315fa9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/ClusterShell/CLI/Clush.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def bind_stdin(worker, display):
"""Create a stdin->port->worker binding: connect specified worker
to stdin with the help of a reader thread and a ClusterShell Port
object."""
assert not sys.stdin.isatty()
assert sys.stdin is not None and not sys.stdin.isatty()
# Create a ClusterShell Port object bound to worker's task. This object
# is able to receive messages in a thread-safe manner and then will safely
# trigger ev_msg() on a specified event handler.
Expand Down Expand Up @@ -932,7 +932,7 @@ def main():
interactive = not len(args) and \
not (options.copy or options.rcopy)
# check for foreground ttys presence (input)
stdin_isafgtty = sys.stdin.isatty() and \
stdin_isafgtty = sys.stdin is not None and sys.stdin.isatty() and \
os.tcgetpgrp(sys.stdin.fileno()) == os.getpgrp()
# check for special condition (empty command and stdin not a tty)
if interactive and not stdin_isafgtty:
Expand Down Expand Up @@ -966,7 +966,8 @@ def main():
task.set_default("USER_handle_SIGUSR1", user_interaction)

task.excepthook = sys.excepthook
task.set_default("USER_stdin_worker", not (sys.stdin.isatty() or \
task.set_default("USER_stdin_worker", not (sys.stdin is None or \
sys.stdin.isatty() or \
options.nostdin or \
user_interaction))
display.vprint(VERB_DEBUG, "Create STDIN worker: %s" % \
Expand Down
12 changes: 8 additions & 4 deletions lib/ClusterShell/Gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ def gateway_main():
logger = logging.getLogger(__name__)
sys.excepthook = gateway_excepthook

if sys.stdin is None:
logger.critical('Gateway failure: sys.stdin is None')
sys.exit(1)

if sys.stdin.isatty():
logger.critical('Gateway failure: sys.stdin.isatty() is True')
sys.exit(1)

logger.debug('Starting gateway on %s', host)
logger.debug("environ=%s", os.environ)

Expand All @@ -343,10 +351,6 @@ def gateway_main():
task.set_default("stdout_msgtree", False)
task.set_default("stderr_msgtree", False)

if sys.stdin.isatty():
logger.critical('Gateway failure: sys.stdin.isatty() is True')
sys.exit(1)

gateway = GatewayChannel(task)
worker = StreamWorker(handler=gateway)
# Define worker._fanout to not rely on the engine's fanout, and use
Expand Down

0 comments on commit 3315fa9

Please sign in to comment.