Hello,<br><br>I am trying to run three deferred LoopingCall chains in parallel.<br>Here is my code below. I am trying to figure out what is the correct way of exiting the polling after I meet some <br>condition that the polling satisfies. Right now I am throwing an exception<br>
which is being caught by an errback. I wait for all three deferred chains to complete <br>via a DeferredList with (defer.gatherResults) and then I add a callback to that in order to stop the reactor.<br><br>class PollingException(twisted.python.failure.Failure):<br>
<br> def __init__(self, var):<br> self.var = var<br><br><br>def poll(*args):<br> print "poll", args<br> raise PollingException(args[1])<br><br>def errorHandle(failure):<br> print "poll exited"<br>
return True<br><br>def stopReactor(result):<br> print "about to stop reactor"<br> reactor.stop()<br><br><br>t1 = task.LoopingCall(poll, "A")<br>d1 = t1.start(1, 3)<br>d1.addErrback(errorHandle)<br>
<br>t2 = task.LoopingCall(poll, "B")<br>d2 = t2.start(2, 3)<br>d2.addErrback(errorHandle)<br><br>t3 = task.LoopingCall(poll, "C")<br>d3 = t3.start(3, 3)<br>d3.addErrback(errorHandle)<br><br>dL = defer.gatherResults([d1, d2, d3])<br>
dL.addCallback(lambda _: reactor.stop())<br><br>reactor.run()<br><br><br><br><br>However, when I run the code and I try to stop the reactor, I get the following exception which I find puzzling.<br><br>poll ('A',)<br>
poll exited<br>poll ('B',)<br>poll exited<br>poll ('C',)<br>poll exited<br>Unhandled error in Deferred:<br>Traceback (most recent call last):<br> File "twisted_poll.py", line 36, in <module><br>
dL.addCallback(lambda _: reactor.stop())<br> File "c:\python25\lib\site-packages\twisted\internet\defer.py", line 191, in addCallback<br> callbackKeywords=kw)<br> File "c:\python25\lib\site-packages\twisted\internet\defer.py", line 182, in addCallbacks<br>
self._runCallbacks()<br>--- <exception caught here> ---<br> File "c:\python25\lib\site-packages\twisted\internet\defer.py", line 317, in _runCallbacks<br> self.result = callback(self.result, *args, **kw)<br>
File "twisted_poll.py", line 36, in <lambda><br> dL.addCallback(lambda _: reactor.stop())<br> File "c:\python25\lib\site-packages\twisted\internet\base.py", line 342, in stop<br> raise RuntimeError, "can't stop reactor that isn't running"<br>
exceptions.RuntimeError: can't stop reactor that isn't running<br><br><br>Thanks very much,<br>-Mike<br>