title: Python OSError: Too many open files
body: <p>I'm using Python 2.7 on Windows XP. </p>
  
  <p>My script relies on tempfile.mkstemp and tempfile.mkdtemp to create a lot of files and directories with the following pattern:</p>
  
  <pre><code>_,_tmp = mkstemp(prefix=section,dir=indir,text=True)
  
  &lt;do something with file&gt;
  
  os.close(_)
  </code></pre>
  
  <p>Running the script always incurs the following error (although the exact line number changes, etc.). The actual file that the script is attempting to open varies.</p>
  
  <pre><code>OSError: [Errno 24] Too many open files: 'path\\to\\most\\recent\\attempt\\to\\open\\file'
  </code></pre>
  
  <p>Any thoughts on how I might debug this? Also, let me know if you would like additional information. Thanks!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here's an example of use:</p>
  
  <pre><code>out = os.fdopen(_,'w')
  out.write("Something")
  out.close()
  
  with open(_) as p:
      p.read()
  </code></pre>