'Reap workers to avoid zombie processes'

def reap_workers(self):

    try:
        while True:
            (wpid, status) = os.waitpid((-1), os.WNOHANG)
            if (not wpid):
                break
            if (self.reexec_pid == wpid):
                self.reexec_pid = 0
            else:
                exitcode = (status >> 8)
                if (exitcode == self.WORKER_BOOT_ERROR):
                    reason = 'Worker    failed    to    boot.'
                    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
                if (exitcode == self.APP_LOAD_ERROR):
                    reason = 'App    failed    to    load.'
                    raise HaltServer(reason, self.APP_LOAD_ERROR)
                worker = self.WORKERS.pop(wpid, None)
                if (not worker):
                    continue
                worker.tmp.close()
                self.cfg.child_exit(self, worker)
    except OSError as e:
        if (e.errno != errno.ECHILD):
            raise
