From: Georg Brandl Date: Sun, 21 Mar 2010 09:51:16 +0000 (+0000) Subject: Update os.kill() emulation example for Windows to use ctypes. X-Git-Tag: v2.7b1~290 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f23f0a2c7ce25890352f7a5a4ec2b5bfd63e4b44;p=python Update os.kill() emulation example for Windows to use ctypes. --- diff --git a/Doc/faq/windows.rst b/Doc/faq/windows.rst index 2d701c843b..353c40055a 100644 --- a/Doc/faq/windows.rst +++ b/Doc/faq/windows.rst @@ -441,13 +441,15 @@ present, and ``getch()`` which gets one character without echoing it. How do I emulate os.kill() in Windows? -------------------------------------- -Use win32api:: +To terminate a process, you can use ctypes:: + + import ctypes def kill(pid): """kill function for Win32""" - import win32api - handle = win32api.OpenProcess(1, 0, pid) - return (0 != win32api.TerminateProcess(handle, 0)) + kernel32 = ctypes.windll.kernel32 + handle = kernel32.OpenProcess(1, 0, pid) + return (0 != kernel32.TerminateProcess(handle, 0)) Why does os.path.isdir() fail on NT shared directories?