From 4a5cfd10852c876ce096ee30ef31b2d67f58d388 Mon Sep 17 00:00:00 2001 From: andrey-panoply Date: Tue, 16 May 2023 17:49:14 +0300 Subject: [PATCH 1/5] Print threading errors to stdout --- panoply/__init__.py | 25 +++++++++++++++++++++++++ panoply/constants.py | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/panoply/__init__.py b/panoply/__init__.py index 94888b0..f19b854 100644 --- a/panoply/__init__.py +++ b/panoply/__init__.py @@ -1,3 +1,28 @@ +from sys import stdout +from traceback import print_exception as _print_exception + from .datasource import * from .sdk import * from .ssh import SSHTunnel + + +def custom_excepthook(args, /): + """ + Handle uncaught Thread.run() exception + and print error text to STDOUT instead of STDERR. + + "It's always assumed that + the runnner is single-threaded and synchronuous such that `result` events + are only assigned to the last executed request". + see https://github.com/panoplyio/legacy-source-wrapper/blob/master/src/sources-runner/index.js#L74 + """ + if args.exc_type == SystemExit: + # silently ignore SystemExit + return + + print(f"Caught an exception in thread:") + _print_exception(args.exc_type, args.exc_value, args.exc_traceback, + file=stdout) + + +threading.excepthook = custom_excepthook diff --git a/panoply/constants.py b/panoply/constants.py index badb4ab..9cf51c9 100644 --- a/panoply/constants.py +++ b/panoply/constants.py @@ -1,2 +1,2 @@ -__version__ = "2.1.2" +__version__ = "2.1.3" __package_name__ = "panoply-python-sdk" From e683a5642adf2f270fff3588ac4dad1fc64ed285 Mon Sep 17 00:00:00 2001 From: andrey-panoply Date: Mon, 22 May 2023 12:04:40 +0300 Subject: [PATCH 2/5] Add console logger with STDOUT stream --- panoply/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/panoply/__init__.py b/panoply/__init__.py index f19b854..b3e243c 100644 --- a/panoply/__init__.py +++ b/panoply/__init__.py @@ -26,3 +26,8 @@ def custom_excepthook(args, /): threading.excepthook = custom_excepthook + +# create console logger and log messages to STDOUT (default stream is STDERR) +logger = logging.getLogger(__name__) +console_handler = logging.StreamHandler(stream=stdout) +logger.addHandler(console_handler) From 92597c1387d9c287a55c26f2d78bde5eced8f5d2 Mon Sep 17 00:00:00 2001 From: andrey-panoply Date: Mon, 22 May 2023 12:21:03 +0300 Subject: [PATCH 3/5] Bump version to 2.2.0 --- panoply/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panoply/constants.py b/panoply/constants.py index 9cf51c9..9b509c2 100644 --- a/panoply/constants.py +++ b/panoply/constants.py @@ -1,2 +1,2 @@ -__version__ = "2.1.3" +__version__ = "2.2.0" __package_name__ = "panoply-python-sdk" From aebade4b76fd15689bb7e55fe8e71bba9fb513b1 Mon Sep 17 00:00:00 2001 From: andrey-panoply Date: Mon, 22 May 2023 15:42:07 +0300 Subject: [PATCH 4/5] Change logger --- panoply/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/panoply/__init__.py b/panoply/__init__.py index b3e243c..5f75e77 100644 --- a/panoply/__init__.py +++ b/panoply/__init__.py @@ -1,3 +1,5 @@ +import logging + from sys import stdout from traceback import print_exception as _print_exception @@ -6,6 +8,9 @@ from .ssh import SSHTunnel +logging.basicConfig(stream=stdout) + + def custom_excepthook(args, /): """ Handle uncaught Thread.run() exception @@ -20,14 +25,9 @@ def custom_excepthook(args, /): # silently ignore SystemExit return - print(f"Caught an exception in thread:") + logging.error(f"Caught an exception in thread:") _print_exception(args.exc_type, args.exc_value, args.exc_traceback, file=stdout) threading.excepthook = custom_excepthook - -# create console logger and log messages to STDOUT (default stream is STDERR) -logger = logging.getLogger(__name__) -console_handler = logging.StreamHandler(stream=stdout) -logger.addHandler(console_handler) From 3ebff190f4fcf0b9c31fb66cb644154451879c1c Mon Sep 17 00:00:00 2001 From: andrey-panoply Date: Mon, 22 May 2023 16:12:20 +0300 Subject: [PATCH 5/5] Add logging format --- panoply/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panoply/__init__.py b/panoply/__init__.py index 5f75e77..91ecc03 100644 --- a/panoply/__init__.py +++ b/panoply/__init__.py @@ -8,7 +8,7 @@ from .ssh import SSHTunnel -logging.basicConfig(stream=stdout) +logging.basicConfig(stream=stdout, format='%(levelname)s: %(message)s') def custom_excepthook(args, /):