title: How to stop python from propagating signals to subprocesses?
body: <p>I'm using python to manage some simulations. I build the parameters and run the program using:</p>
  
  <pre><code>pipe = open('/dev/null', 'w')
  pid = subprocess.Popen(shlex.split(command), stdout=pipe, stderr=pipe)
  </code></pre>
  
  <p>My code handles different signal. Ctrl+C will stop the simulation, ask if I want to save, and exit gracefully. I have other signal handlers (to force data output for example).</p>
  
  <p>What I want is to send a signal (SIGINT, Ctrl+C) to my python script which will ask the user which signal he wants to send to the program.</p>
  
  <p>The only thing preventing the code to work is that it seems that whatever I do, Ctrl+C will be "forwarded" to the subprocess: the code will catch it to and exit:</p>
  
  <pre><code>try:
    &lt;wait for available slots&gt;
  except KeyboardInterrupt:
    print "KeyboardInterrupt catched! All simulations are paused. Please choose the signal to send:"
    print "  0: SIGCONT (Continue simulation)"
    print "  1: SIGINT  (Exit and save)"
    [...]
    answer = raw_input()
    pid.send_signal(signal.SIGCONT)
    if   (answer == "0"):
      print "    --&gt; Continuing simulation..."
    elif (answer == "1"):
      print "    --&gt; Exit and save."
      pid.send_signal(signal.SIGINT)
      [...]
  </code></pre>
  
  <p>So whatever I do, the program is receiving the SIGINT that I only want my python script to see. How can I do that???</p>
  
  <p>I also tried:</p>
  
  <pre><code>signal.signal(signal.SIGINT, signal.SIG_IGN)
  pid = subprocess.Popen(shlex.split(command), stdout=pipe, stderr=pipe)
  signal.signal(signal.SIGINT, signal.SIG_DFL)
  </code></pre>
  
  <p>to run the program but this gives the same result: the program catches the SIGINT.</p>
  
  <p>Thanx!</p>