Open GoogleCodeExporter opened 8 years ago
AFAICT the decorator solution is as *clean* as it gets :)
That said, I would agree that pyev's error handling might be made simpler by
adding an error callback to the loop. But you need to understand that it will
only move the main problem of _you_ handling errors from the watcher callback
to the loop error callback.
What happens now during invocation of pending watchers (in pseudo python code):
try:
watcher.callback()
except Exception as e:
if loop.debug:
loop.stop()
else:
print(e)
The solution I would propose could be expressed as:
try:
watcher.callback()
except Exception as e:
if loop.on_error:
try:
loop.on_error(e)
except Exception as x:
if loop.debug:
loop.stop()
else:
print(x)
else:
if loop.debug:
loop.stop()
else:
print(e)
Hmm... that might make the overall loop invocation error handling (slightly)
slower. Well, if you have a better idea... (maybe I didn't understand what you
meant).
lekma
Original comment by lekma...@gmail.com
on 8 Oct 2012 at 10:27
If the error handler raises an exception it would probably a good idea to
terminate the loop no matter if debug mode is active or not. That usually means
something is very wrong - and ignoring the error is not a good idea then IMO.
Another option besides the custom error handler would be using a standard
python logger to log the exception. This would allow the exception to be logged
properly (i.e. with a stacktrace etc.) without touching any of the loop code.
Original comment by adr...@planetcoding.net
on 8 Oct 2012 at 10:30
Original issue reported on code.google.com by
adr...@planetcoding.net
on 7 Oct 2012 at 1:17