简体   繁体   English

如何在Twisted中解雇延迟?

[英]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 延迟到0x24dv5f5当前结果: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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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