[issue12184] socketserver.ForkingMixin collect_children routine needs to collect only it's children

Charles-François Natali report at bugs.python.org
Thu May 26 14:46:23 CEST 2011


Charles-François Natali <neologix at free.fr> added the comment:

In the common case, I don't think that the os.waitpid(0, 0) is the hot spot, but rather this:

for child in self.active_children:
    os.waitpid(child, os.WNOHANG)

It's called every time, and it's O(number of active children).

os.waitpid(0, 0) is only called when max_children (40) is reached. Also, I'm not sure why it's called without WNOHANG, because that means that we will block until active_children falls below max_children. That's an arbitrary limit, especially since it's not documented.

I've written a first draft patch using process group, that removes active_children and max_children.
The only slightly tricky part is the call to setpgid from the child and from the parent, to avoid a race where the child could try to join a stale PGID.
Note that I assume that setpgid is available on every Unix, since according to http://pubs.opengroup.org/onlinepubs/007908799/xsh/setpgid.html , it's "Derived from the POSIX.1-1988 standard".
Also, according to buildbots' configure logs, it's available everywhere.

----------
keywords: +patch
Added file: http://bugs.python.org/file22124/ss_wait_group.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12184>
_______________________________________


More information about the Python-bugs-list mailing list