[Twisted-Python] async code structure question
Jp Calderone
exarkun at divmod.com
Thu Feb 10 11:24:41 MST 2005
On Thu, 10 Feb 2005 13:08:15 -0500, Itamar Shtull-Trauring <itamar at itamarst.org> wrote:
>
> Do() should return a Deferred that has result when processing is done,
> and then you can Do().addCallback(lambda: self.transport.write("hello"))
> or something.
>
> e.g.
>
> def Do():
> d = deferToThread(foo)
> d.addCallback(processResult)
> return d
>
> or
>
> def Do():
> # processing in this case is waiting for one second
> d = Deferred()
> reactor.callLater(d.callback, 1)
reactor.callLater(1, d.callback, "foo")
But this is much less realistic than the first example :)
Jp
More information about the Twisted-Python
mailing list