首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在callgrind中停止检测

在callgrind中停止检测
EN

Stack Overflow用户
提问于 2012-05-31 06:39:54
回答 1查看 230关注 0票数 0

我正在生成多个进程,并在每个进程中启动插装。当我试图在进程退出之前停止检测时,检测程序似乎挂在shell中,好像进程已经结束,并且它没有要停止检测的进程。代码如下:

代码语言:javascript
复制
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()

如何解决挂起问题?我真的需要停止指令插入吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-31 14:09:01

我用call代替system,参数为shell=True,解决了callgrind_control挂起的问题

代码语言:javascript
复制
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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10825288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档