title: delegate SIGINT signal to child process and then cleanup and terminate the parent
body: <p>I have a main python(testmain.py) script that executes another python script(test.py) using subprocess.Popen command. When I press Ctrl-C , I want the child to exit with exit code 2 and then the parent to display that exit code and then terminate . </p>
  
  <p>I have signal handlers in both parent and child scripts.</p>
  
  <p>testmain.py</p>
  
  <pre><code>def signal_handler(signal, frame):
      print "outer signal handler"
      exit(2)
  signal.signal(signal.SIGINT, signal_handler) 
  
  def execute()
  proc=subprocess.Popen("python test.py",shell=True)
      streamdata=proc.communicate()[0]
      rc=proc.returncode
      print "return code:",rc
  
  execute()
  </code></pre>
  
  <p>test.py</p>
  
  <pre><code>def signal_handler(signal, frame):
      print "exiting: inner function"
      exit(2)
  signal.signal(signal.SIGINT, signal_handler)
  </code></pre>
  
  <p>I checked <a href="https://stackoverflow.com/questions/24936107/delegate-signal-handling-to-a-child-process-in-python">Delegate signal handling to a child process in python</a> that is kind of similar to my question but in that case, the parent is continuing it's execution, which I don't want. </p>
  
  <p>I want to: 1.exit test.py with exit(2) 2.print that exit code in testmain.py 3.exit test.py with exit(2)  </p>
  
  <p>could someone please provide suggestions to do this?
  Thanks. </p>
  
  <p>UPDATE : Handling the signal only in the child (test.py) and checking the return code in parent(testmain.py) will do what I want .</p>
  
  <pre><code>if rc==2:
     print "child was terminated"
     exit(2)
  </code></pre>
  
  <p>but I was wondering if there is a clean way to do this using signal handling.</p>