I am running an executable using the subprocess.Popen
API.
I have also set a timeout since the executable could hang or take too long in the communicate
call. The problem is that on a heavy loaded server it seems like the run times out often. I think it is because it does not get enough CPU time as I run multiple processes in parallel.
I could increase the timeout, however this is a slippery slope as the machine might become even more loaded (it's used as a Jenkins server).
process = subprocess.Popen(cmd, stdout=log, stderr=log, ...)
process.communicate(timeout=timeout)
Is there a way I can refactor this to instead measure CPU time given to the process and timeout based on that?
I've seen questions suggesting timeit.default_timer()
. However I am not sure that'll work for me.