def _start_worker(self, service_id, worker_id): self._slowdown_respawn_if_needed() pid = os.fork() if pid != 0: self._running_services[service_id][pid] = worker_id return # reset parent signals signal.signal(signal.SIGINT, signal.SIG_DFL) signal.signal(signal.SIGALRM, signal.SIG_DFL) signal.signal(signal.SIGTERM, signal.SIG_DFL) signal.signal(signal.SIGHUP, signal.SIG_DFL) # Close write to ensure only parent has it open os.close(self.writepipe) os.close(self.signal_pipe_r) os.close(self.signal_pipe_w) _utils.spawn(self._watch_parent_process) # Reseed random number generator random.seed() # Create and run a new service with _utils.exit_on_exception(): self._current_process = _service.ServiceWorker( self._services[service_id], worker_id, self._graceful_shutdown_timeout) self._run_hooks('new_worker', service_id, worker_id, self._current_process.service) self._current_process.wait_forever()
def _reload(self): with _utils.exit_on_exception(): if self._signal_lock.acquire(False): try: self._on_reload_internal_hook(self) self.reload() finally: self._signal_lock.release()
def _run(self): with _utils.exit_on_exception(): self.run()
def _terminate(self): with _utils.exit_on_exception(), self._signal_lock: self.terminate() sys.exit(0)