def _worker_postfork(self, tmpfd): self.log.info("initializing worker") if self.worker_uid is not None: self.log.info("setting worker uid") os.setuid(self.worker_uid) if self.worker_gid is not None: self.log.info("setting worker gid") os.setgid(self.worker_gid) if self.readiness_notifier is not None: scheduler.end(self.readiness_notifier) scheduler.reset_poller() if self.original: scheduler.schedule(self.worker_inform_ready) self.clear_master_signals() self.apply_worker_signals() for t in self.workers.values(): t.cancel() self.workers = None self.log.info("starting health timer") self.worker_health_timer(tmpfd) self.zombie_checker.cancel() self.worker_postfork()
def _worker_exited(self, pid): wid = self.rev_workers.pop(pid, None) if wid is None: # this could be another master that was created # by a SIGUSR2 handler and then killed off return scheduler.end(self.health_checks.pop(pid)) del self.workers[wid] if pid in self.do_not_revive: self.do_not_revive.discard(pid) else: self.log.fatal("worker %d crashed, starting replacement" % pid) self.worker_crashed(wid, pid) if self.fork_worker(wid): return if self.die_with_last_worker and not self.workers: self.log.info("last worker done, exiting") self.done.set()
def _worker_postfork(self, wid, pid, tmpfd): self.log.info("initializing worker") with io.File(self.control_path(self.WORKER_PIDFILE % wid), 'w') as fp: fp.write(str(os.getpid())) if self.worker_gid is not None: self.log.info("setting worker gid") os.setgid(self.worker_gid) if self.worker_uid is not None: self.log.info("setting worker uid") os.setuid(self.worker_uid) if self.readiness_notifier is not None: scheduler.end(self.readiness_notifier) scheduler.reset_poller() if self.original: scheduler.schedule(self.worker_inform_ready) self.clear_master_signals() self.apply_worker_signals() for t in self.health_checks.values(): scheduler.end(t) self.workers = None self.rev_workers = None self.health_checks = None self.log.info("starting health timer") self.worker_health_timer(tmpfd) self.zombie_checker.cancel() self.worker_postfork(wid, pid)