I have three Python script files (script1.py, script2.py and script3.py) and I want script1.py and script2.py to run simultaneously and script3.py to start only when script2.py is finished (script1.py doesn't have to be finished yet when script3 starts).
I have a code like this to work it out but I'm not sure if I'm doing the right stuff:
import subprocess import multiprocessing def func1(command): subprocess.run(command, shell=True) def func2(command): subprocess.run(command, shell=True) def func3(command): subprocess.run(command, shell=True) if __name__ =='__main__': p1 = multiprocessing.Process(target=func1,args=('python3 script1.py',)) p2 = multiprocessing.Process(target=func2,args=('python3 script2.py',)) p3 = multiprocessing.Process(target=func3,args=('python3 script3.py',)) p1.start() p2.start() p2.join() p3.start() p3.join() p1.join() Is it gonna work? Is there a better way to do this? Is there a rule that I have to join them in the order as they were started?
script3.pyin the p3 line