from twisted.internet import defer
def status(*ds):
return [(getattr(d, 'result', "N/A"), len(d.callbacks)) for d in ds]
def b_callback(arg):
print "b_callback called with arg =", arg
return b
def on_done(arg):
print "on_done called with arg =", arg
return arg
a = defer.Deferred()
b = defer.Deferred()
a.addCallback(b_callback).addCallback(on_done)
status(a, b) # [('N/A', 2), ('N/A', 0)]
a.callback(3) # b_callback called with arg = 3
status(a, b) # [(<Deferred at 0x7f219e4117a0>, 1), ('N/A', 1)]
b.callback(4) # on_done called with arg = 4
status(a, b) # [(4, 0), (None, 0)]
a.callback(3)
之后 b 也有了 on_done
callback。这里没明白。b.callback(4)
之后 a 的 on_done 也执行了,但只输出了一个 on_done called with arg = 4,且 b 的 result 是 None 不是 4 ??
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.