title: Python too many open files (subprocesses)
body: <p>I seem to be having an issue with Python when I run a script that creates a large number of sub processes. The sub process creation code looks similar to:</p>
  
  <p>Code:</p>
  
  <pre><code>def execute(cmd, stdout=None, stderr=subprocess.STDOUT, cwd=None):
      proc = subprocess.Popen(cmd, shell=True, stdout=stdout, stderr=stderr, cwd=cwd)
      atexit.register(lambda: __kill_proc(proc))
      return proc
  </code></pre>
  
  <p>The error message I am receiving is:</p>
  
  <blockquote>
    <p>OSError: [Errno 24] Too many open files</p>
  </blockquote>
  
  <p>Once this error occurs, I am unable to create any further sub processes until kill the script and start it again. I am wondering if the following line could be responsible.</p>
  
  <pre><code>atexit.register(lambda: __kill_proc(proc))
  </code></pre>
  
  <p>Could it be that this line creates a reference to the sub process, resulting in a "file" remaining open until the script exits?</p>