[Twisted-Python] equivalent of flow.Cooperate for deferredGenerator

Matt Goodall matt at pollenation.net
Thu Apr 13 05:06:38 MDT 2006


Manlio Perillo wrote:
> Hi.
> 
> What is the equivalent instruction for pause a deferredGenerator for n
> seconds.

I'm not sure what Cooperate actually does but if you just want to put a
deferredGenerator to sleep for some period of time then something like
this (untested) should work:

    seconds = 5
    d = defer.Deferred()
    reactor.callLater(seconds, lambda: d.callback(None))
    d = defer.waitForDeferred(d)
    yield d
    d.getResult()

That's ugly, but pulling the first 3 or 4 lines of that into a function
would tidy it up a lot.

- Matt

-- 
     __
    /  \__     Matt Goodall, Pollenation Internet Ltd
    \__/  \    w: http://www.pollenation.net
  __/  \__/    e: matt at pollenation.net
 /  \__/  \    t: +44 (0)113 2252500
 \__/  \__/
 /  \          Any views expressed are my own and do not necessarily
 \__/          reflect the views of my employer.




More information about the Twisted-Python mailing list