Better way to patch gevent error handling
This commit is contained in:
parent
a187726ba8
commit
9d048371b7
1 changed files with 5 additions and 4 deletions
|
@ -50,7 +50,7 @@ def handleErrorNotify(*args, **kwargs):
|
||||||
if err.__name__ == "KeyboardInterrupt":
|
if err.__name__ == "KeyboardInterrupt":
|
||||||
shutdown("Keyboard interrupt")
|
shutdown("Keyboard interrupt")
|
||||||
elif err.__name__ != "Notify":
|
elif err.__name__ != "Notify":
|
||||||
logging.error("Unhandled exception 3: %s" % Debug.formatException())
|
logging.error("Unhandled exception: %s" % Debug.formatException(args))
|
||||||
sys.__excepthook__(*args, **kwargs)
|
sys.__excepthook__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,15 +73,16 @@ else:
|
||||||
gevent.Greenlet = gevent.greenlet.Greenlet = ErrorhookedGreenlet
|
gevent.Greenlet = gevent.greenlet.Greenlet = ErrorhookedGreenlet
|
||||||
importlib.reload(gevent)
|
importlib.reload(gevent)
|
||||||
|
|
||||||
def handleGreenletError(self, context, type, value, tb):
|
def handleGreenletError(context, type, value, tb):
|
||||||
if isinstance(value, str):
|
if isinstance(value, str):
|
||||||
# Cython can raise errors where the value is a plain string
|
# Cython can raise errors where the value is a plain string
|
||||||
# e.g., AttributeError, "_semaphore.Semaphore has no attr", <traceback>
|
# e.g., AttributeError, "_semaphore.Semaphore has no attr", <traceback>
|
||||||
value = type(value)
|
value = type(value)
|
||||||
if not issubclass(type, self.NOT_ERROR):
|
|
||||||
|
if not issubclass(type, gevent.get_hub().NOT_ERROR):
|
||||||
sys.excepthook(type, value, tb)
|
sys.excepthook(type, value, tb)
|
||||||
|
|
||||||
gevent.hub.Hub.handle_error = handleGreenletError
|
gevent.get_hub().handle_error = handleGreenletError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
signal.signal(signal.SIGTERM, lambda signum, stack_frame: shutdown("SIGTERM"))
|
signal.signal(signal.SIGTERM, lambda signum, stack_frame: shutdown("SIGTERM"))
|
||||||
|
|
Loading…
Reference in a new issue