I've created a Thread that execute every 60 seconds, just like a Timer or a SetInterval, based on this: Python threading.timer - repeat function every 'n' seconds
It always worked fine on Windows, but now I have to execute this on Linux (Fedora and Ubuntu, for now) and it's just don't work!
I can't wonder why, because it doesn't return any error. And my Shot function works fine out of the Thread.
Here is my code:
class ShotAllTheTime(Thread):
"""
Thread principal que invoca as operações do Client
"""
def __init__(self, event, time_between_shots = 60, *args, **kwargs):
Thread.__init__(self)
self.finished = event
self.time_between_shots = time_between_shots
self.args = args
self.kwargs = kwargs
def cancel(self):
#Termina a thread.
self.finished.set()
def run(self):
while not self.finished.wait(self.time_between_shots):
Shot()
This is how I call the ShotAllTheTime Thread:
def main()
stop_shots = Event()
MyThread = ShotAllTheTime(stop_shots)
MyThread.start()
while 1:
entrada = raw_input("\nEnter 'exit' to exit:")
if entrada == 'exit':
stop_shots.set()
break
sys.exit()
main()