The os.kill() document says “The Windows version of kill() additionally takes process handles to be killed”, but the kill()
function actually does not accept process handles instead of process IDs. Runing the following code on Windows 10 will result in error.
Code to run:
import os, signal
proc_handle = os.spawnl(os.P_NOWAIT, r'C:\Windows\notepad.exe', 'notepad.exe')
os.kill(proc_handle, signal.SIGTERM)
Error message:
Traceback (most recent call last):
File "C:\Users\John\Documents\Python\os_kill_proc_handle.py", line 3, in <module>
os.kill(proc_handle, signal.SIGTERM)
OSError: [WinError 87] The parameter is incorrect