title: Python - Is there a way to wait os.unlink() or os.remove() to finish?
body: <p>I have the following code:</p>
  
  <pre><code>os.remove('_Temp_Dir_\main' + str(i) + '.exe')
  os.rmdir('_Temp_Dir_')
  </code></pre>
  
  <p>Which gives me:</p>
  
  <pre><code>OSError: [WinError 145] Directory is not empty: '_Temp_Dir_'
  </code></pre>
  
  <p>if i put the line</p>
  
  <pre><code>time.sleep(0.05)
  </code></pre>
  
  <p>before <code>os.rmdir()</code>, it works correctly. I think <code>os.remove()</code> isn't fast enough to remove the file. Any way to wait for it to finish its work?</p>