python - twisted: no exception trace if error from a callback -


consider following code:

df = defer.deferred() def hah(_): raise valueerror("4") df.addcallback(hah) df.callback(hah) 

when runs, exception gets eaten. did go? how can displayed? doing defer.setdebugging(true) has no effect.

i ask because other times, printout saying "unhandled error in deferred:". how happen in case? see if add errback df errback gets called exception, want print error , nothing else, , don't want manually add handler every deferred create.

the exception still sitting in deferred. there 2 possible outcomes @ point:

  • you add errback deferred. do, called failure containing exception raised.
  • you let deferred garbage collected (explicitly delete df, or return function, or lose reference in other way). triggers ''unhandled error in deferred'' code.

because errback can added deferred @ time (ie, first point above), deferreds don't otherwise unhandled errors right away. don't know if error unhandled, or unhandled far. it's when deferred garbage collected can sure no 1 else going handle exception, that's when gets logged.

in general, want sure have errbacks on deferreds, precisely because it's hard predict when deferred garbage collected. might long time, means might long time before learn exception if don't have own errback attached.

this doesn't have terrible burden. deferred (a) returned callback on deferred (b) (ie, when chaining happens) pass errors along b. (a) doesn't need errbacks on logging , reporting, (b) does. if have single logical task complicated , involves many asynchronous operations, it's case of deferreds involved in operations should channel results (success or failure) 1 main deferred represents logical operation. need special error handling behavior on 1 deferred, , let handle errors of other deferreds involved.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -