Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fire a deferred in Twisted?

I'm working with twisted. I'm a little bit confused about using deferred objects. I see me correct result in this deferred but I can't work with it.

For example

def hello(defer):
    print(defer)

Just printest me

Deferred at 0x24dv5f5 current result: 44

How can I access this result?

Update

This is my code where I try to fire the deferred

    def handleLoginFailed(self, sid, args):
        d = defer.Deferred()
        d.callback(sid)

        def writeLoginFailed(sid, args):
            print("sid:", sid)
            self.simpleQuery(
                """
                INSERT INTO auth
                    (session, success, username, password, timestamp)
                VALUES (%s, %s, %s, %s, FROM_UNIXTIME(%s))
                """,
                (sid, 0, args['username'],
                    args['password'], self.nowUnix()))
        d.addCallback(writeLoginFailed(sid, args))
like image 536
Denny Crane Avatar asked Jun 06 '13 12:06

Denny Crane


1 Answers

d = Deferred()
d.callback("the result")

def handleTheResult(result):
    print "The Deferred fired, its result is:", result
d.addCallback(handleTheResult)
like image 88
Jean-Paul Calderone Avatar answered Oct 21 '22 20:10

Jean-Paul Calderone