title: How to make python wait untill an ongoing process is completed
body: <p>I am writing a Python script to organize my files in a folder to respective directories. I Want this to run continuously, so I used the <code>while</code> loop to scan for files. but if I try to paste a new file in the folder my script is terminating saying that <code>The process cannot access the file because it is being used by another process</code>. I understand that it stopped because of the process of <strong>pasting files</strong>. Now I want my script to wait until the ongoing process stops</p>
  <p><strong>code sample:</strong></p>
  <pre><code>while(True):
      scan()
      #rest of commands
  </code></pre>
  <p>So I want the <code>scan()</code> function to wait until the process is over</p>
  <p>Thanks in advance</p>