Wait for another python script to finish

I have a python script that ... basically calls another python script. Inside another python script, it spawns some threads ... How do I make a script call until the called script is run?

This is my code:

while(len(mProfiles) < num): print distro + " " + str(len(mProfiles)) mod_scanProfiles.main(distro) time.sleep(180) mProfiles = readProfiles(mFile,num,distro) print "yoyo" 

how can I do something like, wait until mod_scanProfiles.main () and all the threads are completely finished? (I used time.sleep (180) at the moment, but not very well programmed habbit)

+4
source share
1 answer

You want to change the code in mod_scanProfiles.main to block until all its threads are complete.

Assuming you call subprocess.Popen in this function, simply do:

 # in mod_scanPfiles.main: p = subprocess.Popen(...) p.wait() # wait until the process completes. 

If you do not expect your threads to finish, you will also want to call Thread.join ( docs ) to wait for them to complete. For instance:

 # assuming you have a list of thread objects somewhere threads = [MyThread(), ...] for thread in threads: thread.start() for thread in threads: thread.join() 
+4
source

All Articles