kill a process in windows python 2.5
How do i kill a process in windows (xp 32开发者_JAVA百科 bits) in python 2.5? Someone on stackoverlow posted on how to import ctypes and do it but I don't have a ctypes module.
I am running the process in the following way-
ex=Execution(cmd)
#do something
ex.proc.kill()
This gives me an error saying Popen object has no attribute kill. Using os.kill(ex.pid, signal.SIGKILL) gives a similar error.
Among others, I found two ways:
- http://metazin.wordpress.com/2008/08/09/how-to-kill-a-process-in-windows-using-python/
- https://blogs.oracle.com/rajkumar/entry/how_to_kill_a_process
The latter uses the subprocess
module in conjunction with taskkill
. The former win32api.TerminateProcess
.
Popen.kill() is only available after Python 2.6. For 2.5 and earlier, you can use taskkill or the win32api as mentioned by "The MYYN".
精彩评论