Ejemplo n.º 1
0
    def __init__(self):
        """Creates the ServiceManager object

        :param wait_interval: time between each new process spawn
        :type wait_interval: float

        """

        if self._process_runner_already_created:
            raise RuntimeError("Only one instance of ServiceManager per "
                               "application is allowed")
        ServiceManager._process_runner_already_created = True
        super(ServiceManager, self).__init__()

        _utils.setproctitle("%s: master process [%s]" %
                            (_utils.get_process_name(), " ".join(sys.argv)))

        # We use OrderedDict to start services in adding order
        self._services = collections.OrderedDict()

        # Try to create a session id if possible
        try:
            os.setsid()
        except (OSError, AttributeError):
            pass

        signal.signal(signal.SIGINT, self._fast_exit)
        if os.name == 'posix':
            signal.signal(signal.SIGCHLD, self._signal_catcher)
Ejemplo n.º 2
0
    def __init__(self, config, service_id, worker_id, parent_pipe,
                 started_hooks, graceful_shutdown_timeout):
        super(ServiceWorker, self).__init__()
        self._ready = threading.Event()
        if parent_pipe is not None:
            _utils.spawn(self._watch_parent_process, parent_pipe)

        # Reseed random number generator
        random.seed()

        args = tuple() if config.args is None else config.args
        kwargs = dict() if config.kwargs is None else config.kwargs
        self.service = config.service(worker_id, *args, **kwargs)
        self.service._initialize(worker_id)
        if self.service.graceful_shutdown_timeout is None:
            self.service.graceful_shutdown_timeout = graceful_shutdown_timeout

        self.title = "%(name)s(%(worker_id)d) [%(pid)d]" % dict(
            name=self.service.name, worker_id=worker_id, pid=os.getpid())

        # Set process title
        _utils.setproctitle("%(pname)s: %(name)s worker(%(worker_id)d)" %
                            dict(pname=_utils.get_process_name(),
                                 name=self.service.name,
                                 worker_id=worker_id))

        # We are ready tell them
        self._ready.set()
        _utils.run_hooks('new_worker', started_hooks, service_id, worker_id,
                         self.service)
Ejemplo n.º 3
0
    def __init__(self, config, service_id, worker_id, parent_pipe,
                 started_hooks, graceful_shutdown_timeout):
        super(ServiceWorker, self).__init__()
        self._ready = threading.Event()
        _utils.spawn(self._watch_parent_process, parent_pipe)

        # Reseed random number generator
        random.seed()

        args = tuple() if config.args is None else config.args
        kwargs = dict() if config.kwargs is None else config.kwargs
        self.service = config.service(worker_id, *args, **kwargs)
        self.service._initialize(worker_id)
        if self.service.graceful_shutdown_timeout is None:
            self.service.graceful_shutdown_timeout = graceful_shutdown_timeout

        self.title = "%(name)s(%(worker_id)d) [%(pid)d]" % dict(
            name=self.service.name, worker_id=worker_id, pid=os.getpid())

        # Set process title
        _utils.setproctitle(
            "%(pname)s: %(name)s worker(%(worker_id)d)" % dict(
                pname=_utils.get_process_name(), name=self.service.name,
                worker_id=worker_id))

        # We are ready tell them
        self._ready.set()
        _utils.run_hooks('new_worker', started_hooks, service_id, worker_id,
                         self.service)
Ejemplo n.º 4
0
    def __init__(self, wait_interval=0.01, graceful_shutdown_timeout=60):
        """Creates the ServiceManager object

        :param wait_interval: time between each new process spawn
        :type wait_interval: float

        """

        if self._process_runner_already_created:
            raise RuntimeError("Only one instance of ServiceManager per "
                               "application is allowed")
        ServiceManager._process_runner_already_created = True
        super(ServiceManager, self).__init__()

        # We use OrderedDict to start services in adding order
        self._services = collections.OrderedDict()
        self._running_services = collections.defaultdict(dict)
        self._forktimes = []
        self._graceful_shutdown_timeout = graceful_shutdown_timeout
        self._wait_interval = wait_interval

        self._dead = threading.Event()
        # NOTE(sileht): Set it on startup, so first iteration
        # will spawn initial workers
        self._got_sig_chld = threading.Event()
        self._got_sig_chld.set()

        self._child_supervisor = None

        self._hooks = {
            'terminate': [],
            'reload': [],
            'new_worker': [],
            'dead_worker': [],
        }

        _utils.setproctitle("%s: master process [%s]" %
                            (_utils.get_process_name(), " ".join(sys.argv)))

        # Try to create a session id if possible
        try:
            os.setsid()
        except (OSError, AttributeError):
            pass

        self._death_detection_pipe = multiprocessing.Pipe(duplex=False)

        signal.signal(signal.SIGINT, self._fast_exit)
        if os.name == 'posix':
            signal.signal(signal.SIGCHLD, self._signal_catcher)
Ejemplo n.º 5
0
    def __init__(self, config, worker_id, graceful_shutdown_timeout):
        super(ServiceWorker, self).__init__()

        args = tuple() if config.args is None else config.args
        kwargs = dict() if config.kwargs is None else config.kwargs
        self.service = config.service(worker_id, *args, **kwargs)
        self.service._initialize(worker_id)
        if self.service.graceful_shutdown_timeout is None:
            self.service.graceful_shutdown_timeout = graceful_shutdown_timeout

        self.title = "%(name)s(%(worker_id)d) [%(pid)d]" % dict(
            name=self.service.name, worker_id=worker_id, pid=os.getpid())

        # Set process title
        setproctitle.setproctitle(
            "%(pname)s: %(name)s worker(%(worker_id)d)" % dict(
                pname=_utils.get_process_name(), name=self.service.name,
                worker_id=worker_id))
Ejemplo n.º 6
0
    def __init__(self, wait_interval=0.01, graceful_shutdown_timeout=60):
        """Creates the ServiceManager object

        :param wait_interval: time between each new process spawn
        :type wait_interval: float

        """

        if self._process_runner_already_created:
            raise RuntimeError("Only one instance of ServiceManager per "
                               "application is allowed")
        ServiceManager._process_runner_already_created = True
        super(ServiceManager, self).__init__(wait_interval)

        # We use OrderedDict to start services in adding order
        self._services = collections.OrderedDict()
        self._running_services = collections.defaultdict(dict)
        self._forktimes = []
        self._current_process = None
        self._graceful_shutdown_timeout = graceful_shutdown_timeout

        self._hooks = {
            'terminate': [],
            'reload': [],
            'new_worker': [],
        }

        setproctitle.setproctitle(
            "%s: master process [%s]" %
            (_utils.get_process_name(), " ".join(sys.argv)))

        # Try to create a session id if possible
        try:
            os.setsid()
        except OSError:
            pass

        self.readpipe, self.writepipe = os.pipe()

        signal.signal(signal.SIGINT, self._fast_exit)