stopping instrumentation in callgrind
-
11-06-2021 - |
Question
I'm spawning multiple processes and starting the instrumentation in each of them. When I try to stop the instrumentation just before the process exits, the instrumentation program seems to hang in the shell as if the process has already finished and it doesn't have a process to stop the instrumentation for. Here is the code:
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()
How can I solve the hanging problem? Do I really need to stop the instrumentation?
Solution
I solved the callgrind_control
hanging problem by using call
instead of system
, with the parameter 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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow