Exemplo n.º 1
0
    def init_process(self):
        """\
        If you override this method in a subclass, the last statement
        in the function should be to call this method with
        super(MyWorkerClass, self).init_process() so that the ``run()``
        loop is initiated.
        """

        # set current pid
        self.pid = os.getpid()
        
        util.set_owner_process(self.conf.get("uid", os.geteuid()),
                self.conf.get("gid", os.getegid()))

        # Reseed the random number generator
        util.seed()

        # prevent fd inheritance
        util.close_on_exec(self.tmp.fileno())

         # init signals
        self.init_signals()

        util._setproctitle("arbiter [%s]" % self.name)
        self.on_init_process()

        log.debug("Arbiter %s booted on %s", self.name, self.pid)
        self.when_ready()
        # Enter main run loop
        self.booted = True
        self.run()
Exemplo n.º 2
0
    def reload(self):
        """ 
        used on HUP
        """
    
        # exec on reload hook
        self.on_reload()

        OLD__WORKERS = self._WORKERS.copy()

        # don't kill
        to_reload = []

        # spawn new workers with new app & conf
        for child in self._CHILDREN_SPECS:
            if child.child_type != "supervisor":
                to_reload.append(child)

        # set new proc_name
        util._setproctitle("arbiter [%s]" % self.name)
        
        # kill old workers
        for wpid, (child, state) in OLD__WORKERS.items():
            if state:
                if child.child_type == "supervisor":
                    # we only reload suprvisors.
                    sig = signal.SIGHUP
                elif child.child_type == "brutal_kill":
                    sig =  signal.SIGTERM
                else:
                    sig =  signal.SIGQUIT
                self.kill_worker(wpid, sig)
Exemplo n.º 3
0
    def reload(self):
        """ 
        used on HUP
        """

        # exec on reload hook
        self.on_reload()

        OLD__WORKERS = self._WORKERS.copy()

        # don't kill
        to_reload = []

        # spawn new workers with new app & conf
        for child in self._CHILDREN_SPECS:
            if child.child_type != "supervisor":
                to_reload.append(child)

        # set new proc_name
        util._setproctitle("arbiter [%s]" % self.name)

        # kill old workers
        for wpid, (child, state) in OLD__WORKERS.items():
            if state and child.timeout is not None:
                if child.child_type == "supervisor":
                    # we only reload suprvisors.
                    sig = signal.SIGHUP
                elif child.child_type == "brutal_kill":
                    sig = signal.SIGTERM
                else:
                    sig = signal.SIGQUIT
                self.kill_worker(wpid, sig)
Exemplo n.º 4
0
    def init_process(self):
        """\
        If you override this method in a subclass, the last statement
        in the function should be to call this method with
        super(MyWorkerClass, self).init_process() so that the ``run()``
        loop is initiated.
        """

        # set current pid
        self.pid = os.getpid()

        util.set_owner_process(self.conf.get("uid", os.geteuid()),
                               self.conf.get("gid", os.getegid()))

        # Reseed the random number generator
        util.seed()

        # prevent fd inheritance
        util.close_on_exec(self.tmp.fileno())

        # init signals
        self.init_signals()

        util._setproctitle("arbiter [%s]" % self.name)
        self.on_init_process()

        log.debug("Arbiter %s booted on %s", self.name, self.pid)
        self.when_ready()
        # Enter main run loop
        self.booted = True
        self.run()
Exemplo n.º 5
0
    def spawn_child(self, child_spec):
        self.child_age += 1
        name = child_spec.name
        child_type = child_spec.child_type

        child_args = self.conf
        child_args.update(child_spec.args)

        try:
            # initialize child class
            child = child_spec.child_class(
                        child_args,
                        name = name,
                        child_type = child_type, 
                        age = self.child_age,
                        ppid = self.pid,
                        timeout = child_spec.timeout)
        except:
            log.info("Unhandled exception while creating '%s':\n%s",  
                            name, traceback.format_exc())
            return


        self.pre_fork(child)
        pid = os.fork()
        if pid != 0:
            self._WORKERS[pid] = (child, 1)
            return

        # Process Child
        worker_pid = os.getpid()
        try:
            util._setproctitle("worker %s [%s]" % (name,  worker_pid))
            log.info("Booting %s (%s) with pid: %s", name,
                    child_type, worker_pid)
            self.post_fork(child)
            child.init_process()
            sys.exit(0)
        except SystemExit:
            raise
        except:
            log.exception("Exception in worker process:")
            if not child.booted:
                sys.exit(self._WORKER_BOOT_ERROR)
            sys.exit(-1)
        finally:
            log.info("Worker exiting (pid: %s)", worker_pid)
            try:
                child.tmp.close()
            except:
                pass
Exemplo n.º 6
0
    def spawn_child(self, child_spec):
        self.child_age += 1
        name = child_spec.name
        child_type = child_spec.child_type

        child_args = self.conf
        child_args.update(child_spec.args)

        try:
            # initialize child class
            child = child_spec.child_class(child_args,
                                           name=name,
                                           child_type=child_type,
                                           age=self.child_age,
                                           ppid=self.pid,
                                           timeout=child_spec.timeout)
        except:
            log.info("Unhandled exception while creating '%s':\n%s", name,
                     traceback.format_exc())
            return

        self.pre_fork(child)
        pid = os.fork()
        if pid != 0:
            self._WORKERS[pid] = (child, 1)
            return

        # Process Child
        worker_pid = os.getpid()
        try:
            util._setproctitle("worker %s [%s]" % (name, worker_pid))
            log.info("Booting %s (%s) with pid: %s", name, child_type,
                     worker_pid)
            self.post_fork(child)
            child.init_process()
            sys.exit(0)
        except SystemExit:
            raise
        except:
            log.exception("Exception in worker process:")
            if not child.booted:
                sys.exit(self._WORKER_BOOT_ERROR)
            sys.exit(-1)
        finally:
            log.info("Worker exiting (pid: %s)", worker_pid)
            try:
                child.tmp.close()
            except:
                pass
Exemplo n.º 7
0
Arquivo: pool.py Projeto: stsai/pistil
    def reload(self):
        """
        used on HUP
        """

        # exec on reload hook
        self.on_reload()

        # spawn new workers with new app & conf
        for i in range(self.conf.get("num_workers", 1)):
            self.spawn_child(self._SPEC)

        # set new proc_name
        util._setproctitle("master [%s]" % self.name)

        # manage workers
        self.manage_workers()
Exemplo n.º 8
0
    def reload(self):
        """ 
        used on HUP
        """

        # exec on reload hook
        self.on_reload()

        # spawn new workers with new app & conf
        for i in range(self.conf.get("num_workers", 1)):
            self.spawn_child(self._SPEC)
            
        # set new proc_name
        util._setproctitle("master [%s]" % self.name)
        
        # manage workers
        self.manage_workers() 
Exemplo n.º 9
0
Arquivo: pool.py Projeto: stsai/pistil
 def update_proc_title(self):
     util._setproctitle("arbiter [%s running %s workers]" % (self.name,
         self.num_workers))
Exemplo n.º 10
0
 def update_proc_title(self):
     util._setproctitle("arbiter [%s running %s workers]" % (self.name,  
         self.num_workers))