]> granicus.if.org Git - python/commitdiff
Update os.kill() emulation example for Windows to use ctypes.
authorGeorg Brandl <georg@python.org>
Sun, 21 Mar 2010 09:51:16 +0000 (09:51 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 21 Mar 2010 09:51:16 +0000 (09:51 +0000)
Doc/faq/windows.rst

index 2d701c843be0a7383ebb26b5686089aa8a401d6f..353c40055a195b55a47f986ec9aa024af2495237 100644 (file)
@@ -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?