简体   繁体   中英

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))
d = Deferred()
d.callback("the result")

def handleTheResult(result):
    print "The Deferred fired, its result is:", result
d.addCallback(handleTheResult)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM