【发布时间】:2013-01-20 20:04:59
【问题描述】:
我正在尝试使用此函数杀死 Windows 上的 notepad.exe 进程:
import thread, wmi, os
print 'CMD: Kill command called'
def kill():
c = wmi.WMI ()
Commands=['notepad.exe']
if Commands[0]!='All':
print 'CMD: Killing: ',Commands[0]
for process in c.Win32_Process ():
if process.Name==Commands[0]:
process.Terminate()
else:
print 'CMD: trying to kill all processes'
for process in c.Win32_Process ():
if process.executablepath!=inspect.getfile(inspect.currentframe()):
try:
process.Terminate()
except:
print 'CMD: Unable to kill: ',proc.name
kill() #Works
thread.start_new_thread( kill, () ) #Not working
当我这样调用函数时,它就像一个魅力:
kill()
但是在新线程中运行该函数时它会崩溃,我不知道为什么。
【问题讨论】:
-
当你说“它崩溃了”时,你到底是什么意思?
标签: python multithreading wmi