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>&nbsp;&nbsp;&nbsp; def __init__(self, var):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.var = var<br><br><br>def poll(*args):<br>&nbsp;&nbsp;&nbsp; print &quot;poll&quot;, args<br>&nbsp;&nbsp;&nbsp; raise PollingException(args[1])<br><br>def errorHandle(failure):<br>&nbsp;&nbsp;&nbsp; print &quot;poll exited&quot;<br>
&nbsp;&nbsp;&nbsp; return True<br><br>def stopReactor(result):<br>&nbsp;&nbsp;&nbsp; print &quot;about to stop reactor&quot;<br>&nbsp;&nbsp;&nbsp; reactor.stop()<br><br><br>t1 = task.LoopingCall(poll, &quot;A&quot;)<br>d1 = t1.start(1, 3)<br>d1.addErrback(errorHandle)<br>
<br>t2 = task.LoopingCall(poll, &quot;B&quot;)<br>d2 = t2.start(2, 3)<br>d2.addErrback(errorHandle)<br><br>t3 = task.LoopingCall(poll, &quot;C&quot;)<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 (&#39;A&#39;,)<br>
poll exited<br>poll (&#39;B&#39;,)<br>poll exited<br>poll (&#39;C&#39;,)<br>poll exited<br>Unhandled error in Deferred:<br>Traceback (most recent call last):<br>&nbsp; File &quot;twisted_poll.py&quot;, line 36, in &lt;module&gt;<br>
&nbsp;&nbsp;&nbsp; dL.addCallback(lambda _: reactor.stop())<br>&nbsp; File &quot;c:\python25\lib\site-packages\twisted\internet\defer.py&quot;, line 191, in addCallback<br>&nbsp;&nbsp;&nbsp; callbackKeywords=kw)<br>&nbsp; File &quot;c:\python25\lib\site-packages\twisted\internet\defer.py&quot;, line 182, in addCallbacks<br>
&nbsp;&nbsp;&nbsp; self._runCallbacks()<br>--- &lt;exception caught here&gt; ---<br>&nbsp; File &quot;c:\python25\lib\site-packages\twisted\internet\defer.py&quot;, line 317, in _runCallbacks<br>&nbsp;&nbsp;&nbsp; self.result = callback(self.result, *args, **kw)<br>
&nbsp; File &quot;twisted_poll.py&quot;, line 36, in &lt;lambda&gt;<br>&nbsp;&nbsp;&nbsp; dL.addCallback(lambda _: reactor.stop())<br>&nbsp; File &quot;c:\python25\lib\site-packages\twisted\internet\base.py&quot;, line 342, in stop<br>&nbsp;&nbsp;&nbsp; raise RuntimeError, &quot;can&#39;t stop reactor that isn&#39;t running&quot;<br>
exceptions.RuntimeError: can&#39;t stop reactor that isn&#39;t running<br><br><br>Thanks very much,<br>-Mike<br>