title: python multithreading wait till all threads finished
body: <p>This may have been asked in a similar context but I was unable to find an answer after about 20 minutes of searching, so I will ask.</p>
  
  <p>I have written a Python script (lets say: scriptA.py) and a script (lets say scriptB.py)</p>
  
  <p>In scriptB I want to call scriptA multiple times with different arguments, each time takes about an hour to run, (its a huge script, does lots of stuff.. don't worry about it) and I want to be able to run the scriptA with all the different arguments simultaneously, but I need to wait till ALL of them are done before continuing; my code:</p>
  
  <pre><code>import subprocess
  
  #setup
  do_setup()
  
  #run scriptA
  subprocess.call(scriptA + argumentsA)
  subprocess.call(scriptA + argumentsB)
  subprocess.call(scriptA + argumentsC)
  
  #finish
  do_finish()
  </code></pre>
  
  <p>I want to do run all the <code>subprocess.call()</code> at the same time, and then wait till they are all done, how should I do this? </p>
  
  <p>I tried to use threading like the example <a href="http://www.saltycrane.com/blog/2008/09/simplistic-python-thread-example/" rel="noreferrer">here</a>:</p>
  
  <pre><code>from threading import Thread
  import subprocess
  
  def call_script(args)
      subprocess.call(args)
  
  #run scriptA   
  t1 = Thread(target=call_script, args=(scriptA + argumentsA))
  t2 = Thread(target=call_script, args=(scriptA + argumentsB))
  t3 = Thread(target=call_script, args=(scriptA + argumentsC))
  t1.start()
  t2.start()
  t3.start()
  </code></pre>
  
  <p>But I do not think this is right. </p>
  
  <p>How do I know they have all finished running before going to my <code>do_finish()</code>?</p>