【问题标题】:stopping instrumentation in callgrind在 callgrind 中停止检测
【发布时间】:2012-05-30 22:39:54
【问题描述】:

我正在生成多个进程并在每个进程中启动检测。 当我试图在进程退出之前停止检测时,检测程序似乎挂在 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()

如何解决挂起问题? 我真的需要停止检测吗?

【问题讨论】:

    标签: python linux valgrind instrumentation callgrind


    【解决方案1】:

    我通过使用call而不是system解决了callgrind_control挂起问题,参数shell=True

    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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-22
      • 2012-08-25
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      • 2015-06-28
      相关资源
      最近更新 更多