Here’s the Python code to run an arbitrary command returning its stdout data, or raise an exception on non-zero exit codes: communicate is used to wait for the process to exit: The subprocess module does not support timeout–ability to kill a process running for more than X number of seconds–therefore, communicate may take forever to run. What is the simplest
Tag: multithreading
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