I have a python script that calls another python script. Inside the other python script it spawns some threads.How do I make the calling script wait until the called script is completely done running?
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 do I wait until mod_scanProfiles.main() and all threads are completely finished? ( I used time.sleep(180) for now but its not good programming habit)
You want to modify the code in
mod_scanProfiles.mainto block until all it’s threads are finished.Assuming you make a call to
subprocess.Popenin that function just do:If you’re not currently waiting for your threads to end you’ll also want to call
Thread.join(docs) to wait for them to complete. For example: