As discussed with Guido in issue #80
(https://code.google.com/p/tulip/issues/detail?id=80),
I'm proposing a strawman design for having a user definable event loop
handler for unhandled exceptions.
Two new API points:
- "loop.set_exception_handler(callback)"
Sets 'callback' as a new unhandled error handler for the event loop
'loop'. The signature of callback should be '(loop, exception,
context)'
where: 'loop' parameter is the current event loop running; 'exception'
is the unhandled exception object; 'context' is a string (str),
that will be the basic context information, like
"unhandled exception in add_reader callback" (the kind of information
that usually goes to the log title).
It's OK to call 'loop.stop()' or 'loop.call_*' methods from the
handler.
If a user set handler raises an exception, that exception will be
handled by the default event loop exception handler (that will
simply log it)
- "loop.restore_default_exception_handler()"
Restores exception handler to the default one.
Default exception handler just logs the error with
'loop.logger.exception()'
Let's discuss.
Thanks,
Yury