I want to make a small function that does some fetching in the background for my application, so I want my application to continue normal execution after calling this (so this should be non-blocking). I want this to run on a scheduled thread every X seconds. To do so I have the following:
def start(self):
sync_thread = threading.Timer(30, self.readMessages(self.queue, self.client))
sync_thread.start()
where queue and client are initialized in the __init__ function and assigned to self.
The first start for the thread and invocation to my readMessages function works well, though currently after 30 seconds I get the following error:
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.8/threading.py", line 1254, in run
self.function(*self.args, **self.kwargs)
TypeError: 'NoneType' object is not callable
Any idea what to do with it, or is there a better way to do this?
threading.Timer. Instead you currently call the function once immediately and pass its return value, that's probably not what you want. Try a lambda instead.