title: Python, remove directory: error File exists
body: <p>I need to develop a script that will launch some computations. A want this script  to handle ^C correctly by deleting some temporary directory. I have tried several versions of code in the signal_handler:</p>
  
  <pre><code>shutil.rmtree(self.temp)
  </code></pre>
  
  <p>or even</p>
  
  <pre><code>os.system("rm -rf " + self.temp)
  </code></pre>
  
  <p>when I am interrupting the execution and the handler is called to remove the directory, I am getting errors like :</p>
  
  <pre><code>OSError: [Errno 17] File exists : 'foo' 
  </code></pre>
  
  <p>or</p>
  
  <pre><code>rm: Unable to remove directory foo: File exists
  </code></pre>
  
  <p>After execution, the directory I want to delete is empty, and I can delete it with a <code>rm -r</code> in the shell. However, if I execute the code :</p>
  
  <pre><code>for f  in os.listdir(self.temp):
      os.remove(os.path.join(self.temp,f))
  
  for f in os.listdir(self.temp):
      print f
  
  os.rmdir(self.temp)
  </code></pre>
  
  <p>I am, of course, getting errors, but the second loop finds this file: <code>.nfsA13D3</code></p>
  
  <p>Anyone have a solution to my problem ?
  Thank you !</p>