Better way to patch gevent error handling

This commit is contained in:
shortcutme 2019-11-19 01:42:00 +01:00
parent a187726ba8
commit 9d048371b7
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 5 additions and 4 deletions

View File

@ -50,7 +50,7 @@ def handleErrorNotify(*args, **kwargs):
if err.__name__ == "KeyboardInterrupt":
shutdown("Keyboard interrupt")
elif err.__name__ != "Notify":
logging.error("Unhandled exception 3: %s" % Debug.formatException())
logging.error("Unhandled exception: %s" % Debug.formatException(args))
sys.__excepthook__(*args, **kwargs)
@ -73,15 +73,16 @@ else:
gevent.Greenlet = gevent.greenlet.Greenlet = ErrorhookedGreenlet
importlib.reload(gevent)
def handleGreenletError(self, context, type, value, tb):
def handleGreenletError(context, type, value, tb):
if isinstance(value, str):
# Cython can raise errors where the value is a plain string
# e.g., AttributeError, "_semaphore.Semaphore has no attr", <traceback>
value = type(value)
if not issubclass(type, self.NOT_ERROR):
if not issubclass(type, gevent.get_hub().NOT_ERROR):
sys.excepthook(type, value, tb)
gevent.hub.Hub.handle_error = handleGreenletError
gevent.get_hub().handle_error = handleGreenletError
try:
signal.signal(signal.SIGTERM, lambda signum, stack_frame: shutdown("SIGTERM"))