python - 停止 callgrind 中的检测

标签 python linux valgrind instrumentation callgrind

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

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

最佳答案

我通过使用 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()

关于python - 停止 callgrind 中的检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10825288/

相关文章:

python - 比较 csv 文件中的两行 - Python

python - 新 BlobServiceClient 中的旧 BlockBlobService.get_blob_to_bytes 被什么替代?

python - 为什么 Python 正则表达式不能处理格式化的 HTML 字符串?

c++ - Live555 RTSP服务器不使用UDP

Linux 链接文件夹

Python,sigaction(2) 可用吗?

python - 为什么在 for 循环中使用 PIL 的 Image.paste 时出现图像重叠问题?

memory-management - 如何在centos 5.5中安装valgrind 3.9.0

c - 大小为 8 的无效读/写

c++ - ubuntu 上的静态链接 pthread 导致未初始化的值跳转(valgrind)