[Twisted-Python] Wrapping functions that return deferreds
Ross Burton
ross at burtonini.com
Wed Apr 11 03:42:47 MDT 2007
Hi,
I have a library that has a call() method, which returns a Deferred. My
application used to just use .addCallback() but obviously that doesn't
have any error handling. I then switched to .addCallbacks() so that I
could call a common error handler (to pop up a dialog) but that got
tedious to add to every invocation so I thought I'd be cunning and wrap
the call() method.
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)
However, this doesn't work: I get the standard unhandled error in
deferred handling. Can anyone spot the mistake I'm making?
Thanks,
Ross
--
Ross Burton mail: ross at burtonini.com
jabber: ross at burtonini.com
www: http://www.burtonini.com./
PGP Fingerprint: 1A21 F5B0 D8D0 CFE3 81D4 E25A 2D09 E447 D0B4 33DF
More information about the Twisted-Python
mailing list