0

I am trying to implement a timer structure which runs a function periodically. To do that, I used threading.Timer object like below:

class AClass:

    def function(self):
        print('Begins ...')
        # some operations here ...
        print('Ends!')

    def trigger(self):
        self.market_listener_thread = threading.Timer(DATA_COLLECTOR_FREQUENCY, self.listen, [], {}).start()

class MainClass:
    def anotherFunction:
        aClass = AClass()
        aClass.trigger()

Here my function runs once and prints Begins ... and Ends!. But it does not run for a second time and also does not produce an error, warning anything. What is wrong here?

JollyRoger
  • 737
  • 1
  • 12
  • 38
  • How do you call `MainClass.anotherFunction`? A `threading.Timer` object will only run once, when started. – jofrev Jan 22 '20 at 13:04
  • @jofrev Yes, I didn't know that it calls once, I thought it is similar to the Timer in java. Thanks. – JollyRoger Jan 22 '20 at 13:09

0 Answers0