Improve global exception handler log messages

* Merge pull request #4980

* Improve global exception handler log messages
This commit is contained in:
jack1142 2021-05-19 15:36:16 +02:00 committed by GitHub
parent e2f0ac582b
commit 356922f4de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -446,13 +446,18 @@ def global_exception_handler(red, loop, context):
""" """
Logs unhandled exceptions in other tasks Logs unhandled exceptions in other tasks
""" """
msg = context.get("exception", context["message"]) exc = context.get("exception")
# These will get handled later when it *also* kills loop.run_forever # These will get handled later when it *also* kills loop.run_forever
if not isinstance(msg, (KeyboardInterrupt, SystemExit)): if exc is not None and isinstance(exc, (KeyboardInterrupt, SystemExit)):
if isinstance(msg, Exception): return
log.critical("Caught unhandled exception in task:\n", exc_info=msg) # Maybe in the future we should handle some of the other things
else: # that the default exception handler handles, but this should work fine for now.
log.critical("Caught unhandled exception in task: %s", msg) log.critical(
"Caught unhandled exception in %s:\n%s",
context.get("future", "event loop"),
context["message"],
exc_info=exc,
)
def red_exception_handler(red, red_task: asyncio.Future): def red_exception_handler(red, red_task: asyncio.Future):