title: Waiting till external process has finished writing the file
body: <p>I am using <a href="https://metamap.nlm.nih.gov" rel="nofollow noreferrer">metamap</a> in a project as an external program. Complete code in the project is written in Python. At one place in my code I have to pass input file as an argument to metamap and then read the output file metamap generates. I am calling metamap as follows:</p>
  
  <pre><code>command = '/bin/metamap --silent --sldiID temp_input'
  subprocess.call(command, shell=True)
  </code></pre>
  
  <p>In above case, output file is generated by the name temp_input.out in current working directory. I then need to process the contents of this output file. Issue I am currently facing is that python code moves forward considering output file to be empty. How can I ensure that output file is completely written and only then python code moves forward. </p>
  
  <p>As of now, I am doing following which I feel is not the right way or cleanest way to achieve the above.</p>
  
  <pre><code>while fileExists == False:
      if os.path.isfile(outputFileName):
          fileExists = os.stat(outputFileName).st_size != 0
  </code></pre>