From a6cdf0352329094933dc48ac41b61c71e88d87fa Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Wed, 4 Dec 2024 20:28:20 +0300 Subject: [PATCH] [+] fix exit status for commands 1. fix intercept_output when the process has died before select poll has been started; --- python/online/fxreader/pr34/commands.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/python/online/fxreader/pr34/commands.py b/python/online/fxreader/pr34/commands.py index 765a2a4..679820c 100644 --- a/python/online/fxreader/pr34/commands.py +++ b/python/online/fxreader/pr34/commands.py @@ -132,8 +132,11 @@ def intercept_output( break t2 = t1.poll(100) - if len(t2) == 1 and (t2[0][1] & select.POLLIN) > 0 and \ - not (isinstance(last_data, bytes) and len(last_data) == 0): + if ( + len(t2) == 1 and (t2[0][1] & select.POLLIN) > 0 and \ + not (isinstance(last_data, bytes) and len(last_data) == 0) or + not current_subprocess.poll() is None + ): t3 = current_subprocess.stdout.peek() t4: bytes = current_subprocess.stdout.read(len(t3)) @@ -1557,6 +1560,12 @@ def pass_ssh_osx(argv): last_chunk = chunk break + assert not p.poll() is None + + if p.poll() != 0: + logger.error(p.stderr.read()) + sys.exit(p.poll()) + assert not last_chunk is None assert last_chunk['returncode'] == 0 @@ -3844,7 +3853,7 @@ class Command(enum.StrEnum): def commands_cli( argv: Optional[list[str]] = None -) -> None: +) -> int: if argv is None: argv = sys.argv[1:] @@ -3933,14 +3942,14 @@ def commands_cli( else: raise NotImplementedError except SystemExit: - pass + raise except Exception: msg = 'not implemented\n%s' % traceback.format_exc() logging.error(msg) - - if not msg is None: - custom_notify(msg=msg) + finally: + if not msg is None: + custom_notify(msg=msg) if __name__ == '__main__': - commands_cli() \ No newline at end of file + sys.exit(commands_cli()) \ No newline at end of file