title: Measure CPU time during Python subprocess.Popen call
body: <p>I am running an executable using the <code>subprocess.Popen</code> API.</p>
  <p>I have also set a timeout since the executable could hang or take too long in the <code>communicate</code> 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.</p>
  <p>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).</p>
  <pre><code>process = subprocess.Popen(cmd, stdout=log, stderr=log, ...)
  process.communicate(timeout=timeout)
  </code></pre>
  <p>Is there a way I can refactor this to instead measure CPU time given to the process and timeout based on that?</p>
  <p>I've seen questions suggesting <code>timeit.default_timer()</code>. However I am not sure that'll work for me.</p>