Doubts related to subprocess.Popen()

Jeff McNeil jeff at
Tue Jan 20 17:01:18 CET 2009

On Jan 20, 9:19 am, srinivasan srinivas <sri_anna... at>
> Do parent process will have different file descriptor in it for each subprocesses or paprent uses a single file descriptor for all?
> I really want to know creation of each subprocess will occupy an entry in parents'file descriptor table. B'cos if i create more than 200 subprocesses, i am getting 'Too many open files' error.
> Thanks,
> Srini
> ----- Original Message ----
> From: Mark Wooding <m... at>
> To: python-l... at
> Sent: Tuesday, 20 January, 2009 6:16:17 PM
> Subject: Re: Doubts related to subprocess.Popen()
> srinivasan srinivas <sri_anna... at> writes:
> > Does subprocess.Popen() count a new open file for each suprocess? I
> > mean does it occupy an entry in file descriptor table of parent
> > process?  If so, wat is each file descriptor connected to?
> On Unix, subprocess.Popen will use up a file descriptor in the parent
> for each use of subprocess.PIPE.  The descriptor in question is one end
> of a pipe; the child process holds the other end.
> I guess the situation is similar on Windows, but I don't know for sure.
> -- [mdw]
> --
>       Add more friends to your messenger and enjoy! Go to

Have you upped your open files limit?  My test script:

import subprocess

procs = []
for i in xrange(400):
        stdin=subprocess.PIPE, stdout=subprocess.PIPE,

By default, 'ulimit -n' returns 1024, which is the number of open
files allowed.  Running the test script without changing it results

Traceback (most recent call last):
  File "", line 9, in <module>
  File "/usr/lib/python2.5/", line 593, in __init__
    errread, errwrite)
  File "/usr/lib/python2.5/", line 1002, in
    errpipe_read, errpipe_write = os.pipe()
OSError: [Errno 24] Too many open files

Now, up that limit to 8192 via ulimit -n, and run the script again:

[root at marvin jeff]# ulimit -n 8192
[root at marvin jeff]# python
[root at marvin jeff]#



More information about the Python-list mailing list