1

My LoopingCall task stops when it executes an errorcallback and I want to restart it.

My code looks something like this but I am not sure if I am doing it right or which would be the best way

from twisted.internet.task import LoopingCall
from twisted.internet import reactor

PROCESS_INTERVAL = 1

def periodic_task():
    print notDefined

def periodic_task_crashed(error):
    print "periodic task crashed"

lc = LoopingCall(periodic_task)
d = lc.start(PROCESS_INTERVAL)
d.addErrback(periodic_task_crashed)

reactor.run()

Then for now in my error callback I do this...

def periodic_task_crashed(reason):
    d = lc.start(PROCESS_INTERVAL)
    d.addErrback(periodic_task_crashed)

Is this the right way to do it? Could it enter in a recursive error loop?

lapinkoira
  • 8,320
  • 9
  • 51
  • 94
  • "`...`" is a syntax error in Python, so I'm not sure what it is you're proposing here. http://sscce.org – Glyph Nov 18 '15 at 20:06
  • Ofc it's saying syntax error, Imagine it just prints something, my question is about how to restart the task inside def periodic_task_crashed(reason): – lapinkoira Nov 19 '15 at 07:55
  • You may handle and report exceptions in periodic_task itself. – monoid Nov 19 '15 at 16:02
  • The example still doesn't run. Please provide a single example that exhibits the behavior that you don't expect. Keep in mind that many of us answer LOTS of questions, so having each question in a format where we don't need to do a bunch of extra set-up work to combine various bits of code in the way we *hope* the asker intended us to combine them makes it much, much easier to answer. – Glyph Nov 20 '15 at 08:34
  • I think it's a very simple and basic twisted code, anyway, just added the missing imports and voilà, you have a working example now, wasnt hard right? Now, if you run this, and it crash in the periodic_task I want to restart the periodic_task in the error callback – lapinkoira Apr 05 '16 at 10:31

0 Answers0