title: Python for loop flow when calling a time consuming function
body: <p>I have implemented the following code:</p>
  
  <pre><code>lines=[]
      with open('path_to_file', 'r+') as source:
          for line in source:
              line = line.replace('\n','').strip()
              if line.split()[-1] != 'sent':
                  # do some operation on line without 'sent' tag
                  upload(data1.zip)
                  upload(data2.zip) 
                  do_operation(line)
                  # tag the line
                  line += '\tsent'
              line += '\n'
              # temporary save lines in a list
              lines.append(line)
          # move position to start of the file
          source.seek(0)
          # write back lines to the file
          source.writelines(lines)
  </code></pre>
  
  <p>I am calling upload methods in a section <code>#do some operation with lines without sent tag</code> to upload data to the cloud. As the data is a bit large (around 1GB), it takes a while to finish the upload. In the mean time, does the for loop go ahead to call <code>upload(data2)</code>? I am getting errors as I cannot upload simultaneously.</p>
  
  <p>If yes, how can I avoid this?</p>
  
  <p>EDIT:::</p>
  
  <p>I have changed upload function to return status as done after uploading. So, how can I modify my main loop so that it will wait after calling <code>upload(data1.zip)</code> and then move on to <code>upload(data2.zip)</code>. I want to synchronize.. </p>