diff --git a/panoply/__init__.py b/panoply/__init__.py index 94888b0..91ecc03 100644 --- a/panoply/__init__.py +++ b/panoply/__init__.py @@ -1,3 +1,33 @@ +import logging + +from sys import stdout +from traceback import print_exception as _print_exception + from .datasource import * from .sdk import * from .ssh import SSHTunnel + + +logging.basicConfig(stream=stdout, format='%(levelname)s: %(message)s') + + +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 + + 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 diff --git a/panoply/constants.py b/panoply/constants.py index badb4ab..9b509c2 100644 --- a/panoply/constants.py +++ b/panoply/constants.py @@ -1,2 +1,2 @@ -__version__ = "2.1.2" +__version__ = "2.2.0" __package_name__ = "panoply-python-sdk"