title: Wait until function finish executing in Python
body: <p>I am new to Python</p>
  
  <p>I have the codes below:</p>
  
  <p>Inside my for there is another for loop then that 2nd for loop calls a function that does another for loop.  Now I want the 2nd for loop to wait until the 3rd loops finish its job.  How to do that?</p>
  
  <p>Thanks</p>
  
  <pre><code>def GetArea(img):
      os.chdir("C:\RJC Files\Thesis\Biometrics Thesis\Raw Data\Pics\PickedImages\\" + str(x) + "\\Process")
      for file2 in glob.glob("*.png"):
          # DO SOMETHING 
          # TAKE SOMETIME TO FINISH HERE.
  -----------------------------------------------------------     
  for x in range(1, 2):
      os.chdir("C:\RJC Files\Thesis\Biometrics Thesis\Raw Data\Pics\PickedImages\\" + str(x) + "\\Area")
      for file in glob.glob("*.png"):
          img = cv2.imread(file, 0)
  
          GetArea(img)
  </code></pre>