[issue36829] Add sys.unraisablehook() to custom how "unraisable exceptions" are logged
STINNER Victor
report at bugs.python.org
Wed May 22 17:45:57 EDT 2019
STINNER Victor <vstinner at redhat.com> added the comment:
In PR 13490, Thomas Grainger proposed a cool context manager:
@contextlib.contextmanager
def throw_unraisable_exceptions():
unraisable = None
old_hook = sys.unraisablehook
def hook(exc):
nonlocal unraisable
unraisable = exc
sys.unraisablehook = hook
try:
yield
if unraisable is not None:
raise unraisable
finally:
unraisable = None
sys.unraisablehook = old_hook
It allows to raise an unraisable exception :-D Example:
try:
with support.throw_unraisable_exceptions():
...
except Exception as e:
... # the exception is now here
I don't need such context manager right now, but I like the fact that it becomes possible to write such context manager :-)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36829>
_______________________________________
More information about the Python-bugs-list
mailing list