示例#1
0
    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()
示例#2
0
 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()
示例#3
0
 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()
示例#4
0
 def _run(self):
     with _utils.exit_on_exception():
         self.run()
示例#5
0
 def _terminate(self):
     with _utils.exit_on_exception(), self._signal_lock:
         self.terminate()
         sys.exit(0)
示例#6
0
 def _run(self):
     with _utils.exit_on_exception():
         self.run()
示例#7
0
 def _terminate(self):
     with _utils.exit_on_exception(), self._signal_lock:
         self.terminate()
         sys.exit(0)