Skip to content

Commit 266fdde

Browse files
remote: client: fix empty sys.excepthook error work around
The work around introduced with [1] makes labgrid-client exit with exit code 120. This happens due to sys.stderr being closed prematurely and Py_FinalizeEx() thus failing to flush stderr [2]. Instead of closing stderr, add a sys.excepthook indirection which also prevents the empty excepthook error from being displayed and should also allow actual errors to be displayed [3]. That means we can add it unconditionally. [1] 2dc889c ("remote/client: suppress gRPC error message on shutdown") [2] https://hg.python.org/cpython/rev/6b08429a3932 [3] grpc/grpc#36655 (comment) Fixes: 2dc889c ("remote/client: suppress gRPC error message on shutdown") Signed-off-by: Bastian Krause <[email protected]>
1 parent e8aadae commit 266fdde

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

labgrid/remote/client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
from ..driver import Mode, ExecutionError
4949
from ..logging import basicConfig, StepLogger
5050

51+
# This is a workround for the gRPC issue
52+
# https://github.com/grpc/grpc/issues/38679.
53+
# Since Python 3.12, an empty exception message is printed from gRPC
54+
# during shutdown, although nothing seems to go wrong. As this is
55+
# confusing for users, suppress the message by adding an indirection.
56+
sys.excepthook = lambda type, value, traceback: sys.__excepthook__(type, value, traceback)
57+
5158

5259
class Error(Exception):
5360
pass
@@ -2169,13 +2176,6 @@ def main():
21692176
except Exception: # pylint: disable=broad-except
21702177
traceback.print_exc(file=sys.stderr)
21712178
exitcode = 2
2172-
if not args.debug:
2173-
# This is a workround for the gRPC issue
2174-
# https://github.com/grpc/grpc/issues/38679.
2175-
# Since Python 3.12, an empty exception message is printed from gRPC
2176-
# during shutdown, although nothing seems to go wrong. As this is
2177-
# confusing for users, suppress the message by closing stderr.
2178-
os.close(sys.stderr.fileno())
21792179
exit(exitcode)
21802180
else:
21812181
parser.print_help(file=sys.stderr)

0 commit comments

Comments
 (0)