Skip to content

Instantly share code, notes, and snippets.

View sils's full-sized avatar

Lasse Schuirmann sils

View GitHub Profile
@sils
sils / process-interrupter.py
Last active August 29, 2015 14:26 — forked from Makman2/process-interrupter.py
How to interrupt a process correctly in windows so catch and finally get executed.
from multiprocessing import Process, Queue
from time import sleep
import ctypes
# WINDOWS ONLY!!!
def interrupt_process(pid):
CTRL_C_EVENT = 0x0
ctypes.windll.kernel32.GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid)
# DON'T USE THIS!!! THIS WON'T WORK AND GENERATES A COMPLETELY DIFFERENT