[Twisted-Python] Re: LoopingCall question

Steve Holden steve at holdenweb.com
Fri Jun 27 23:27:02 EDT 2008


Itamar Shtull-Trauring wrote:
> 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
>              self.result.callback(r)

What am I missing that stops the above line from raising AttributeError?

>          else:
>              self.go()
> 
>     def _failed(self, f):
>         self.result.errback(f)
>         del self.result
> 
> 
> def loopUntil(delay, check):
>     l = _LoopUntil(delay, check)
>     r = l.result
>     l.go()
>     return r

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/





More information about the Twisted-Python mailing list