[Twisted-Python] LoopingCall question

Itamar Shtull-Trauring itamar at itamarst.org
Fri Jun 27 09:44:07 EDT 2008

On Wed, 2008-06-25 at 23:29 -0400, Mike Preshman wrote:
> Hello,
> I am trying to run three deferred LoopingCall chains in parallel.
> Here is my code below. I am trying to figure out what is the correct
> way of exiting the polling after I meet some 
> condition that the polling satisfies.

You needn't use LoopingCall, if it's unsuitable - assuming Twisted 8.1:

from twisted.internet import defer, reactor, task

class _LoopUntil(object):

    def __init__(self, delay, check):
        self.delay = delay
        self.check = check
        self.result = defer.Deferred()

    def go(self):
        task.deferLater(reactor, self.delay, check).addCallbacks(
            self._gotResult, self._failed)
    def _gotResult(self, r):
         if r:
             d = self.result
             del self.result

    def _failed(self, f):
        del self.result

def loopUntil(delay, check):
    l = _LoopUntil(delay, check)
    r = l.result
    return r

More information about the Twisted-Python mailing list