Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#5731 enhancement closed wontfix (wontfix)

Allow custom unhandled error collector

Reported by: bersace Owned by:
Priority: normal Milestone:
Component: core Keywords: deferred
Cc: Branch:
Author: Launchpad Bug:

Description

Hi,

I didn't found any proposition to allow custom handling of Unhandled error in Deferred, here is one.

Say you want a simple behaviour : stop the reactor if ever there is an unhandled error in a Deferred. Currently, there is no way for the code de provide a kind of global errback. I suggest to add an entry point to register such kind of errback.

I prototyped a solution by adding two functions : setErrorCollector and restoreErrorCollector. setErrorCollector takes as single parameter a callable called with DebugInfo object when it is garbage collected.

Attached is the prototype. Just run it to see it in action. It basically register a custom error collector, and triggers à unhandled error. The custom error collector just stop the reactor.

I agree that stopping the reactor is not that useful. But one can redirect the error to frontend, and other error handling.

Regards,
Étienne BERSAC

Attachments (1)

unhandled_error_collector.py (1.5 KB) - added by bersace 2 years ago.
Prototype of custom error collector

Download all attachments as: .zip

Change History (3)

Changed 2 years ago by bersace

Prototype of custom error collector

comment:1 Changed 2 years ago by exarkun

  • Resolution set to wontfix
  • Status changed from new to closed

You can do this with twisted.python.log.addObserver.

comment:2 Changed 2 years ago by itamar

The logging documentation, however, could be improved to have a section explicitly giving an example of doing this; you might want to open a ticket for that.

Note: See TracTickets for help on using tickets.