[Twisted-Python] Wrapping functions that return deferreds

Antoine Pitrou antoine.pitrou at wengo.com
Wed Apr 11 04:05:37 MDT 2007


Le mercredi 11 avril 2007 à 10:42 +0100, Ross Burton a écrit :
> def wrap_deferred (func):
>     def wrapped(*args, **kwargs):
>         d = func (*args, **kwargs)
>         d.addErrback (handle_twisted_error)
>         return d
>     return wrapped
> 
> # flickr is the object, call is the method I'm overriding
> flickr.call = wrap_deferred (flickr.call)
> 
> # Then later in my app
> flickr.call(foo).addCallback(handleFoo)

Since you add the errback before adding the callback, errors happening
in handleFoo will not get caught by the errback.







More information about the Twisted-Python mailing list