- #1
ChrisVer
Gold Member
- 3,378
- 464
Hi, I have created the following code:
well, the run_proc(name, locker) function is supposed to be running an executable file I have, with several input variables determined by the set name variable. I also pass the locker for the multiprocessing.
the main() function does the following; it creates 2 processes (I want to run the executable two times in parallel with different configurations), and starts them.
The problem is that the executable treats similar output in the same way, and so I generally receive "errors" (eg producing the same root files and writing histos or graphs into them, unable to delete them etc) if I don't use the Locks. If I use the Lock, on the other hand, my program becomes as slow as can be... I tested the performance of time by running twice -in a sequential manner- the run_proc (commented out lines between triple quotes).
Is there a way to get over it? Thanks.
Python:
import subprocess
import threading
import multiprocessing
import timedef run_proc( name ,locker):
#locker.acquire()
cmd = './Executable -a -b -m %s -p Low -bins=100 --max=%s -c %s channel%s'%(name[0],name[1],name[2],name[3])
subprocess.call(cmd,shell=True)
#locker.release()
def main():
arguments = ([500, 0.1 , 100, 500], [500,0.1,150,500])
'''
t1 =time.time()
for argument in arguments:
run_proc(argument, 'h')
print("Conventional way: ",time.time()-t1)
'''
print('STARTING MULTIPROCESSING')
t3=time.time()
locker=''
#locker = multiprocessing.Lock()
proc1 = multiprocessing.Process(target=run_proc, args=(arguments[0],locker))
proc2 = multiprocessing.Process(target=run_proc, args=(arguments[1],locker))
proc1.start()
proc2.start()
proc1.join()
proc2.join()
print("Multiprocessing way: ",time.time()-t3)if __name__=="__main__":
main()
well, the run_proc(name, locker) function is supposed to be running an executable file I have, with several input variables determined by the set name variable. I also pass the locker for the multiprocessing.
the main() function does the following; it creates 2 processes (I want to run the executable two times in parallel with different configurations), and starts them.
The problem is that the executable treats similar output in the same way, and so I generally receive "errors" (eg producing the same root files and writing histos or graphs into them, unable to delete them etc) if I don't use the Locks. If I use the Lock, on the other hand, my program becomes as slow as can be... I tested the performance of time by running twice -in a sequential manner- the run_proc (commented out lines between triple quotes).
Is there a way to get over it? Thanks.