title: Why are two exceptions thrown when using subprocess.run()?
body: <p>I am using python subprocess.run() to process some command. I want to capture output/error/return code, and want to have timeout if the command is blocked.
  The code is simple:</p>
  
  <pre><code>cmd = "ping 1.1.1.1 -n 5"
  subprocess.run(cmd, shell=True, timeout=2)
  </code></pre>
  
  <p>But the result confuses me, why are two exception thrown?</p>
  
  <pre><code>Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
  [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import subprocess
  &gt;&gt;&gt; cmd = "ping 1.1.1.1 -n 5"
  &gt;&gt;&gt; subprocess.run(cmd, shell=True, timeout=2)
  PING 5 (0.0.0.5) 56(124) bytes of data.
  Traceback (most recent call last):
    File "/usr/lib/python3.6/subprocess.py", line 425, in run
      stdout, stderr = process.communicate(input, timeout=timeout)
    File "/usr/lib/python3.6/subprocess.py", line 863, in communicate
      stdout, stderr = self._communicate(input, endtime, timeout)
    File "/usr/lib/python3.6/subprocess.py", line 1560, in _communicate
      self.wait(timeout=self._remaining_time(endtime))
    File "/usr/lib/python3.6/subprocess.py", line 1469, in wait
      raise TimeoutExpired(self.args, timeout)
  subprocess.TimeoutExpired: Command 'ping 1.1.1.1 -n 5' timed out after 1.999514610040933 seconds
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python3.6/subprocess.py", line 430, in run
      stderr=stderr)
  subprocess.TimeoutExpired: Command 'ping 1.1.1.1 -n 5' timed out after 2 seconds
  &gt;&gt;&gt; 
  </code></pre>