Skip to content

Instantly share code, notes, and snippets.

@ironpythonbot
Created December 9, 2014 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironpythonbot/e3c20532b5f796e5b8d5 to your computer and use it in GitHub Desktop.
Save ironpythonbot/e3c20532b5f796e5b8d5 to your computer and use it in GitHub Desktop.
CodePlex Issue #35020 Plain Text Attachments
from subprocess import Popen, CREATE_NEW_PROCESS_GROUP
import ctypes
import signal
import sys
import time
def receive():
def handler(signum, frame):
print 'Received signal', signum
signal.signal(signal.SIGBREAK, handler)
print 'Started'
while True:
pass
def use_signal():
proc = Popen([sys.executable, __file__, 'receive'],
creationflags=CREATE_NEW_PROCESS_GROUP)
time.sleep(1)
proc.send_signal(signal.CTRL_BREAK_EVENT)
time.sleep(1)
proc.terminate()
def use_ctypes():
proc = Popen([sys.executable, __file__, 'receive'],
creationflags=CREATE_NEW_PROCESS_GROUP)
time.sleep(1)
ctypes.windll.kernel32.GenerateConsoleCtrlEvent(
signal.CTRL_BREAK_EVENT, proc.pid)
time.sleep(1)
proc.terminate()
if __name__ == '__main__':
locals()[sys.argv[1]]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment