<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; background-color: rgb(255, 255, 255); ">I have a question on LoopCall.<br><br>I have a process that uses a sequence of LoopCalls, once one finishes<br>
I call the next to check for the next critical event to continue:<br><br>e.g.<br><br> def checkForAvailableProfile(self):<br> profile = fs_profiles_manager.get_next_available_profile()<br> if profile is None:<br>
return<br> else:<br> self.checkForAvailableProfileLoop.stop()<br><br> self.profile = profile<br><br> logging.debug("using profile: %s", self.profile['name'])<br><br>
self.ff = FirefoxProcess(self.profile, self.params)<br> self.ff.run()<br><br> self.checkForEventsFileLoop = LoopingCall(self.checkIfEventsFileExists)<br> self.checkForEventsFileLoop.start(0.5)<br>
self.state = self.STATE_WAIT_FOR_EVENTS<br><br>====================================================<br><br>The problem is that I'm getting errors, errors when I try to call stop<br>when stop perhaps has already been called.<br>
I want advice on how to manage LoopCalls. So far I'm using state variables.<br>e.g.<br>self.state = self.STATE_WAIT_FOR_EVENTS<br><br>if something goes haywire or if the process is done I have a function<br>that cleans up all the LoopCalls so it's not checking constantly:<br>
<br> def cleanExit(self):<br> if self.state == self.STATE_WAIT_FOR_PROFILE:<br> self.checkForAvailableProfileLoop.stop()<br> elif self.state == self.STATE_WAIT_FOR_EVENTS:<br> self.checkForEventsFileLoop.stop()<br>
elif self.state == self.STATE_WAIT_FOR_PROC_KILLED:<br> self.checkIfFirefoxWasKilledLoop.stop()<br><br> self.ff.cleanExit()<br><br><br>the above code is what I believe is causing my exceptions, but how<br>
else do I check for the LoopCalls?<br><br><br><br>=====================================================<br><br>2011-08-31 12:30:11-0700 [FiresharkProtocol,1278,127.0.0.1] Unhandled Error<br> Traceback (most recent call last):<br>
File "/usr/lib/python2.6/dist-packages/twisted/application/app.py",<br>line 348, in runReactorWithLogging<br> reactor.run()<br> File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py",<br>
line 1170, in run<br> self.mainLoop()<br> File "/usr/lib/python2.6/dist-packages/twisted/internet/base.py",<br>line 1182, in mainLoop<br> self.doIteration(t)<br> File "/usr/lib/python2.6/dist-packages/twisted/internet/selectreactor.py",<br>
line 140, in doSelect<br> _logrun(selectable, _drdw, selectable, method, dict)<br> --- <exception caught here> ---<br> File "/usr/lib/python2.6/dist-packages/twisted/python/log.py",<br>line 84, in callWithLogger<br>
return callWithContext({"system": lp}, func, *args, **kw)<br> File "/usr/lib/python2.6/dist-packages/twisted/python/log.py",<br>line 69, in callWithContext<br> return context.call({ILogContext: newCtx}, func, *args, **kw)<br>
File "/usr/lib/python2.6/dist-packages/twisted/python/context.py",<br>line 59, in callWithContext<br> return self.currentContext().callWithContext(ctx, func, *args, **kw)<br> File "/usr/lib/python2.6/dist-packages/twisted/python/context.py",<br>
line 37, in callWithContext<br> return func(*args,**kw)<br> File "/usr/lib/python2.6/dist-packages/twisted/internet/selectreactor.py",<br>line 156, in _doReadOrWrite<br> self._disconnectSelectable(selectable, why, method=="doRead")<br>
File "/usr/lib/python2.6/dist-packages/twisted/internet/posixbase.py",<br>line 194, in _disconnectSelectable<br> selectable.connectionLost(f)<br> File "/usr/lib/python2.6/dist-packages/twisted/internet/tcp.py",<br>
line 519, in connectionLost<br> protocol.connectionLost(reason)<br> File "/usr/sbin/fireshark.py", line 101, in connectionLost<br> self.cleanExit()<br> File "/usr/sbin/fireshark.py", line 43, in cleanExit<br>
self.checkIfFirefoxWasKilledLoop.stop()<br> File "/usr/lib/python2.6/dist-packages/twisted/internet/task.py",<br>line 171, in stop<br> assert self.running, ("Tried to stop a LoopingCall that was "<br>
exceptions.AssertionError: Tried to stop a LoopingCall that was not running.<br><br><br></span>