How to kill subprocess python in windows
Question: How would I go about killing a process on Windows?

I am starting the process with

    
    
        self.p = Process(target=self.GameInitialize, args=(testProcess,))
        self.p.start()
    

I have tried

    
    
    self.p.kill()
    self.p.terminate()
    os.kill(self.p.pid, -1)
    os.killpg(self.p.pid, signal.SIGTERM)  # Send the signal to all the process groups
    

Errors

    
    
    Process Object has no Attribute kill
    Process Object has no Attribute terminate
    Access Denied
    

I cannot use `.join.`


Answer: On windows, `os.killpg` will not work because it sends a signal to the process
ID to terminate. This is now how you kill a process on Windows, instead you
have to use the win32 API's `TerminateProcess` to kill a process.

So, you can kill a process by the following on windows:

    
    
    import signal
    os.kill(self.p.pid, signal.CTRL_C_EVENT)
    

If the above does not work, then try `signal.CTRL_BREAK_EVENT` instead.

