我正在生成多个进程,并在每个进程中启动插装。当我试图在进程退出之前停止检测时,检测程序似乎挂在shell中,好像进程已经结束,并且它没有要停止检测的进程。代码如下:
from os import system,fork,getpid
from glob import glob
from sys import exit
for filename in glob("py/*.py"):
f=fork()
if f==0:
system("callgrind_control --instr=on "+str(getpid()))
execfile(filename,{})
system("callgrind_control --instr=off "+str(getpid()))
exit()如何解决挂起问题?我真的需要停止指令插入吗?
发布于 2012-05-31 14:09:01
我用call代替system,参数为shell=True,解决了callgrind_control挂起的问题
from os import system,fork,getpid
from glob import glob
from subprocess import call
from multiprocessing import Process
def caller(filename):
pid=getpid()
call(["callgrind_control","--instr=on",str(pid)],shell=True)
execfile(filename,{})
call(["callgrind_control","--instr=off",str(pid)],shell=True)
for filename in glob("py/*.py"):
p=Process(target=caller,args=(filename,))
p.start()
p.join()https://stackoverflow.com/questions/10825288
复制相似问题