-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exception in error handler leads to FFI garbage collection fatal Python error #1482
Comments
Please don't assign to the class. It is documented that you can assign to the instance, e.g., def handleError(self, context, type, value, tb):
print("Hub error:", sys.exc_info()[0].__name__) Please do use the provided type, value, and traceback arguments. They're there for a reason. Making those minor fixes to the program solves the problem: import gevent.monkey
import gevent.threadpool
gevent.monkey.patch_all()
pool = gevent.threadpool.ThreadPool(1)
def handleError(context, t, v, tb):
print("Hub error:", t, v, tb)
gevent.get_hub().handle_error = handleError
def openFile():
open("nonexistent.txt")
try:
gevent.spawn(openFile).get()
except Exception as err:
print("Greenlet error:", err)
try:
pool.apply(openFile)
except Exception as err:
print("Pool err", err) $ GEVENT_LOOP=libuv python /tmp/foo.py
Hub error: <class 'FileNotFoundError'> [Errno 2] No such file or directory: 'nonexistent.txt' <traceback object at 0x1088caeb0>
Greenlet error: [Errno 2] No such file or directory: 'nonexistent.txt'
Hub error: <class 'FileNotFoundError'> [Errno 2] No such file or directory: 'nonexistent.txt' <traceback object at 0x107b14370>
Pool err [Errno 2] No such file or directory: 'nonexistent.txt' Note that there is the tuple NOT_ERROR that you can assign to as well. It's commonly set globally (i.e., on the class) for particular applications, but you can also set it on an instance. If you always want to ignore some exceptions, that's the best way to do it. import gevent.monkey
import gevent.threadpool
gevent.monkey.patch_all()
pool = gevent.threadpool.ThreadPool(1)
gevent.get_hub().NOT_ERROR += (FileNotFoundError,)
def openFile():
open("nonexistent.txt")
try:
gevent.spawn(openFile).get()
except Exception as err:
print("Greenlet error:", err)
try:
pool.apply(openFile)
except Exception as err:
print("Pool err", err) $ GEVENT_LOOP=libuv python /tmp/foo.py
Greenlet error: [Errno 2] No such file or directory: 'nonexistent.txt'
Pool err [Errno 2] No such file or directory: 'nonexistent.txt' |
Thanks for the suggestions, but it does not solves the topic starter issue: if there is an error in the handleError function, then it will lead to Fatal Python error instead of "During handling of the above exception, another exception occurred:" |
That's correct. Don't raise exceptions from there. That's low-level functionality called when the system is in an uncertain state. |
… stopped in the middle of a callback from the event loop and then raised an exception. This could happen if the hub's ``handle_error`` function was poorly customized, for example. Fixes #1482
… stopped in the middle of a callback from the event loop and then raised an exception. This could happen if the hub's ``handle_error`` function was poorly customized, for example. Fixes #1482 Direct error handling through the loop in the unexpected-but-closed case as well.
… stopped in the middle of a callback from the event loop and then raised an exception. This could happen if the hub's ``handle_error`` function was poorly customized, for example. Fixes #1482 Direct error handling through the loop in the unexpected-but-closed case as well.
Description:
I want to suppress handled errors happened in threads.
What I've run:
I can get rid of the fatal error by avoid using
sys.exc_info()
(It does not work if error happens in other thread), but it took me a while realizing why the crash is happening.Also looking for better way to suppress caught errors printing to output other than overriding
gevent.hub.Hub.handle_error
The text was updated successfully, but these errors were encountered: