How to stop subprocesses from copying listening sockets

Rick van Hattem Rick at youtellme.com
Thu Dec 25 23:18:29 EST 2008


On Friday 26 December 2008 04:05:43 Roy Smith wrote:
> In article <mailman.6204.1230258299.3487.python-list at python.org>,
>
>  Rick van Hattem <Rick at youtellme.com> 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