title: Is it safe to remove the containing directory after a file in it is opened?
body: <p>I have some code that needs to return a file object and also clean up the containing directory, e.g.:</p>
  
  <pre><code>def create_file():
      # create a temp directory: temp_dir
      # generate a file inside the directory: filename
  
      file_obj = open(filename, 'rb')
      shutil.rmtree(temp_dir)
      return file_obj
  </code></pre>
  
  <p>Is it safe to remove the containing directory if I have the file handle (the result of <code>open()</code>) ?</p>