title: Send Ctrl-C to remote processes started via subprocess.Popen and ssh
body: <p><strong>How do I send a <code>Ctrl-C</code> to multiple <code>ssh -t</code> processes in <code>Popen()</code> objects?</strong></p>
  
  <p>I have some Python code that kicks off a script on a remote host:</p>
  
  <pre><code># kickoff.py
  
  # i call 'ssh' w/ the '-t' flag so that when i press 'ctrl-c', it get's
  # sent to the script on the remote host.  otherwise 'ctrol-c' would just
  # kill things on this end, and the script would still be running on the
  # remote server
  a = subprocess.Popen(['ssh', '-t', 'remote-host', './script.sh', 'a'])
  a.communicate()
  </code></pre>
  
  <p>That works great, but I need to kick off multiple scripts on the remote host:</p>
  
  <pre><code># kickoff.py
  
  a = subprocess.Popen(['ssh', '-t', 'remote-host', './script.sh', 'a'])
  b = subprocess.Popen(['ssh', '-t', 'remote-host', './script.sh', 'b'])
  a.communicate()
  b.communicate()
  </code></pre>
  
  <p>The result of this is that <code>Ctrl-C</code> doesn't reliably kill everything, and my terminal always gets garbled afterwards (I have to run 'reset').  So how can I kill both remote scripts when the main one is killed?</p>
  
  <p>Note: I'm trying to avoid logging into the remote-host, searching for 'script.sh' in the process list, and sending a SIGINT to both of the processes.  I just want to be able to press <code>Ctrl-C</code> on the kickoff script, and have that kill both remote processes.  A less optimal solution may involve deterministically finding the PID's of the remote scripts, but I don't know how to do that in my current set-up.</p>
  
  <p>Update: the script that gets kicked off on the remote server actually starts up several children processes, and while killing the <code>ssh</code> does kill the original remote script (probably b/c of SIGHUP), the children tasks are not killed.</p>