title: python 3.5 - subprocess.run still running after the script was terminated
body: <p>Why after I terminate a python script with <code>ctrl+c</code> while the command <code>subprocess.run('knife ec2 server create...', shell=True, check=True)</code> is running from this script, the control returns to the terminal session but after a few min/sec the shell command reappears in the terminal session and the shell command from <code>subprocess.run</code> still running?</p>
  
  <p>I think I saw the same issue with <code>os.system</code>, for example <code>os.system('ping 8.8.8.8')</code> .</p>
  
  <p><code>^C</code></p>
  
  <pre><code>Waiting for EC2 to create the instance.....^CTraceback (most recent call last):
    File "t.py", line 177, in &lt;module&gt;
      subprocess.run(command, shell=True, check=True)
    File "/usr/lib/python3.5/subprocess.py", line 695, in run
      stdout, stderr = process.communicate(input, timeout=timeout)
    File "/usr/lib/python3.5/subprocess.py", line 1064, in communicate
      self.wait()
    File "/usr/lib/python3.5/subprocess.py", line 1658, in wait
      (pid, sts) = self._try_wait(0)
    File "/usr/lib/python3.5/subprocess.py", line 1608, in _try_wait
      (pid, sts) = os.waitpid(self.pid, wait_flags)
  KeyboardInterrupt
  $ ..............................................................................done
  
  SSH Target Address: ec2()
  Doing old-style registration with the validation key at /etc/chef/validation.pem...
  Delete your validation key in order to use your user credentials instead
  </code></pre>
  
  <p>I tried also the below code but I got an error:</p>
  
  <pre><code>command = ('knife ec2 server create -N ' + fullname + ' -f ' + instance_type + ' -i ' + pem_file)...
  
  p = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE)
  while True:
      out = p.stderr.read(1)
      if out == '' and p.poll() != None:
          break
      if out != '':
          sys.stdout.write(out)
          sys.stdout.flush()
  </code></pre>
  
  <p>error: </p>
  
  <pre><code>`sys.stdout.write(out) TypeError: write() argument must be str, not bytes'
  </code></pre>
  
  <p>Is there a simple way to run a shell command with <code>python</code> like <code>Ruby</code> with <code>system()</code> ?</p>
  
  <p>Thanks</p>