Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ff24c8e

Browse files
committed
Merged revisions 79181 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r79181 | georg.brandl | 2010-03-21 10:51:16 +0100 (So, 21 Mär 2010) | 1 line Update os.kill() emulation example for Windows to use ctypes. ........
1 parent 718ce2c commit ff24c8e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

Doc/faq/windows.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,15 @@ present, and ``getch()`` which gets one character without echoing it.
445445
How do I emulate os.kill() in Windows?
446446
--------------------------------------
447447

448-
Use win32api::
448+
To terminate a process, you can use ctypes::
449+
450+
import ctypes
449451

450452
def kill(pid):
451453
"""kill function for Win32"""
452-
import win32api
453-
handle = win32api.OpenProcess(1, 0, pid)
454-
return (0 != win32api.TerminateProcess(handle, 0))
454+
kernel32 = ctypes.windll.kernel32
455+
handle = kernel32.OpenProcess(1, 0, pid)
456+
return (0 != kernel32.TerminateProcess(handle, 0))
455457

456458

457459
Why does os.path.isdir() fail on NT shared directories?

0 commit comments

Comments
 (0)