title: Using module 'subprocess' with timeout
body: <p>Here's the Python code to run an arbitrary command returning its <code>stdout</code> data, or raise an exception on non-zero exit codes:</p>
  
  <pre><code>proc = subprocess.Popen(
      cmd,
      stderr=subprocess.STDOUT,  # Merge stdout and stderr
      stdout=subprocess.PIPE,
      shell=True)
  </code></pre>
  
  <p><code>communicate</code> is used to wait for the process to exit:</p>
  
  <pre><code>stdoutdata, stderrdata = proc.communicate()
  </code></pre>
  
  <p>The <code>subprocess</code> module does not support timeout--ability to kill a process running for more than X number of seconds--therefore, <code>communicate</code> may take forever to run.</p>
  
  <p>What is the <strong>simplest</strong> way to implement timeouts in a Python program meant to run on Windows and Linux?</p>