I want to fire off a function every 0.5 seconds and be able to start and stop and reset the timer. I’m not too knowledgeable of how Python threads work and am having difficulties with the python timer. However, I keep getting RuntimeError: threads can only be started once when I execute threading.timer.start() twice. Is there a work around for
Tag: python-multithreading
Python – appending to same file from multiple threads
I’m writing an app that appends lines to the same file from multiple threads. I have a problem in which some lines are appended without a new line. Any solution for this? Answer The solution is to write to the file in one thread only.
How to get the return value from a thread?
The function foo below returns a string ‘foo’. How can I get the value ‘foo’ which is returned from the thread’s target? The “one obvious way to do it”, shown above, doesn’t work: thread.join() returned None. Answer In Python 3.2+, stdlib concurrent.futures module provides a higher level API to threading, including passing return values or exceptions from a worker thread
Timeout on a function call
I’m calling a function in Python which I know may stall and force me to restart the script. How do I call the function or what do I wrap it in so that if it takes longer than 5 seconds the script cancels it and does something else? Answer You may use the signal package if you are running on