I want to use a function to launch a timer with different frequencies for each of the threads that I open. I do not know if this is possible. Could you help me out?
import threading import logging logger = logging.getLogger(__name__) lock = threading.Lock() def f(freq): with lock: logger.info('f') threading.Timer(freq, f(freq)).start() print(freq) if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s %(threadName)s] %(message)s', datefmt='%H:%M:%S') freq = [5,10,15] for i in range(0, len(freq)): threading.Thread(target=f(freq[i])).start()
This is an example I'm trying. I execute a thread for each frequency, and I call the function to which the frequency happened. When I execute it, execution is blocked in the first timer. I think it's because the thread has the same target always, but how could I do it just to use a function that calls me caad timer? There are going to be a few executions and creating a function for each thread is unfeasible.
Thank you very much.