Error in os.kill() Document

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

This is probably best filed as an issue at GitHub - python/cpython: The Python programming language, if you haven’t already, and propose either a documentation change PR (more likely) or a code fix PR (possible, but likely not a good idea).

The OP indeed opened an issue (and I tagged you since I’m no Windows expert :')): Behaviour of os.kill() on Windows may be misunderstood · Issue #125298 · python/cpython · GitHub

1 Like

Thanks. I’ve been offline for the last week and I haven’t braved my GitHub notifications yet :laughing: