title: sending sigint between processes running on separate consoles Windows 7 and Python3
body: <p>I have inherited a test executive that launches test scripts in their own instance of Python, in their own console. The instance of python communicates with the test executive via tcp/ip connection. Currently, if the user stops the script via the test executive, the test executive does a taskkill on the pid of the python instance running the script. This prevents running any clean up function that would normally execute if the script execution completes on its own. I'm trying to rectify this by sending a SIGINT or some other signal to the python instance via the pid of said instance. Then in my test scripts it will have a handle function that will raise the KeyboardInterrupt execption which the scripts will be coded to catch and then execute the clean up function. I tried testing this out using python 3. I have 2 scripts that I run from separate python instances/consoles to best simulate how it would work. One script, os_stop.py, defines the handler function to raise the KeyboardInterrupt if the SIGINT signal is received. This script also prints its pid and runs a a loop displaying an output messages every 5 seconds just to simulate the running of a test script. The other script, send_stop.py, sends the SIGINT to the pid of the first script (note: the pid is passed as a parameter to the script). When executed, send_stop.py does cause os_stop.py to stop, but it doesn't raise the interrupt. I'm guessing a kill is just being executed and the SIGINT is not just being received by the first script. Below is the script code. Any help would be greatly apprecited:</p>
  <p>'''</p>
  <pre><code>os_stop.py
  ---------
  import os
  import time
  import signal
  
  print(&quot;pid - {}&quot;.format(os.getpid()))
  
  def handler(signum, frame):
      print(&quot;CAUGHT SIGNAL!!!!&quot;)
      raise KeyboardInterrupt
  
  signal.signal(signal.SIGINT, handler)
  
  FIVE_SECS = 5
  elapsed = 5
  start_time = time.time()
  try:
      while True:
          if elapsed &gt;= FIVE_SECS:
              print(&quot;Waiting ...&quot;)
              elapsed = 0
              start_time = time.time()
          else:
              elapsed = time.time() - start_time
          time.sleep(.1)
  except KeyboardInterrupt:
      print(&quot;Stopped by user&quot;)
  except signal.SIGINT:
      print(&quot;HERE&quot;)
  </code></pre>
  <p>'''</p>
  <p>'''</p>
  <pre><code>send_stop.py
  ------------
  
  import os
  import sys
  import signal
  
  def send_sigint(pid):
      os.kill(pid, signal.SIGINT)
      
  send_sigint(int(sys.argv[1]))
  </code></pre>
  <p>'''</p>