How to stop subprocesses from copying listening sockets

Rick van Hattem Rick at
Fri Dec 26 05:18:29 CET 2008

On Friday 26 December 2008 04:05:43 Roy Smith wrote:
> In article <mailman.6204.1230258299.3487.python-list at>,
>  Rick van Hattem <Rick at> wrote:
> > Recently I've started building a program that spawns new processes when
> > requested via http, since the http interface doesn't need to be fancy
> > I've just used the BaseHTTPServer module for this, but... it seems I'm
> > running into a little problem. When spawning a new process (which forks
> > itself into a daemon, but isn't too relevant in this case) the listening
> > socket is copied to the new process.
> The standard solution to this problem is to close all descriptors after
> forking and before doing the exec.  You can tell subprocess.Popen() to do
> this by call it with "close_fds=True".

Thank you very much, I completely forgot about the close_fds argument.

That will fix the problem nicely :)

More information about the Python-list mailing list