
I use a wrapper functions as follows to specify the callback argument of addCallback() and addErrback().
def reqConnLostCallbk(result, arg_self): arg_self.lost_conn()
def reqConnLostErrbk(failure, arg_self): arg_self.lost_conn()
... inside a class method d.addCallback(reqConnLostCallbk, self) d.addErrback(reqConnLostErrbk, self)
def lost_conn(self): // cleanup pass
Is there an alternative and/or cleaner solution to specify a class method as a callback or errback?
-Arun

On 06/05/2011 10:44 AM, Phil Mayers wrote:
Is there an alternative and/or cleaner solution to specify a class method as a callback or errback?
Just pass the instance method directly to addCallback:
d.addCallback(someclass.lost_conn)
You can either specify a bound class method or an unbound. I guess you'd like to have a bound callback, but I don't know your entire example.
d.addCallback(some_object.lost_conn)
obj_callback = some_object.method_name # bound method
class_callback = some_class.method_name # unbound method
so the usage would be obj_callback(args)
or
class_callback(object, args)

Thank you for the responses. Specifying the bound instance method as the callback works. (I remember it did not work for me many months ago, hence my post). Works now.
Thanks, -Arun
--- On Sat, 6/4/11, A Desai ardesai@yahoo.com wrote:
From: A Desai ardesai@yahoo.com Subject: Class methods as callbacks/errbacks To: twisted-web@twistedmatrix.com Date: Saturday, June 4, 2011, 9:31 PM
I use a wrapper functions as follows to specify the callback argument of addCallback() and addErrback().
def reqConnLostCallbk(result, arg_self): arg_self.lost_conn()
def reqConnLostErrbk(failure, arg_self): arg_self.lost_conn()
... inside a class method d.addCallback(reqConnLostCallbk, self) d.addErrback(reqConnLostErrbk, self)
def lost_conn(self): // cleanup pass
Is there an alternative and/or cleaner solution to specify a class method as a callback or errback?
-Arun
participants (3)
-
A Desai
-
Gelonida N
-
Phil Mayers