I discovered Python recently and even more recently the Twisted module.
I have a problem with the Twisted reactor and I would like to understand for which reason my program freezes.
Here the code which should loop forever :
from twisted.internet import reactor from twisted.internet import task
class reactorProb(object): def __init__(self): self.count = 5 self._callback = task.LoopingCall(self.Heartbeat) self._callback.start(1, now = False) def Heartbeat(self): print "Top" self.count -= 1 if (self.count == 0): print "Exit" self._callback.stop() del self._callback reactor.stop()
while (True): rp = reactorProb() print "Enter into reactor.run()" reactor.run() print "Leave from reactor.run()"
I got this:
Enter into reactor.run() Top Top Top Top Top Exit Leave from reactor.run() Enter into reactor.run() Top Top Top Top Top Exit
Thus I start first once the reactor, I stop it then I start again and it freezes instead of stopping it the reactor.
Could somebody explain me it why?
Thank you in advance.