'Internal routine to wait for children that have exited.'

def collect_children(self):

    if (self.active_children is None):
        return
    while (len(self.active_children) >= self.max_children):
        try:
            (pid, status) = os.waitpid(0, 0)
        except os.error:
            pid = None
        if (pid not in self.active_children):
            continue
        self.active_children.remove(pid)
    for child in self.active_children:
        try:
            (pid, status) = os.waitpid(child, os.WNOHANG)
        except os.error:
            pid = None
        if (not pid):
            continue
        try:
            self.active_children.remove(pid)
        except ValueError as e:
            raise ValueError(('%s.    x=%d    and    list=%r' % (e.message, pid, self.active_children)))
