Example #1
0
    def stop(self, signum=None, frame=None):
        """
        Stop the zygote master. Steps:
          * Ask all zygotes to kill and wait on their children
          * Wait for zygotes to exit
          * Kill anything left over if necessary
        """
        if self.stopped:
            return
        # kill all of the workers
        self.logger.info('stopping all zygotes and workers')
        pids = set()
        for zygote in self.zygote_collection:
            pids.add(zygote.pid)
            self.logger.debug('requesting shutdown on %d', zygote.pid)
            zygote.request_shut_down()

        self.logger.debug('setting self.stopped')
        self.stopped = True

        self.logger.debug('master is stopping. will not try to update anymore.')
        signal.signal(signal.SIGHUP, signal.SIG_IGN)

        self.logger.debug('stopping io_loop.')
        if getattr(self, 'io_loop', None) is not None:
            self.io_loop.stop()

        self.logger.info('waiting for workers to exit before stoping master.')
        wait_for_pids(pids, self.WAIT_FOR_KILL_TIME, self.logger, kill_pgroup=True)
        self.logger.info('all zygotes exited; good night')

        self.really_stop(0)
Example #2
0
 def kill_workers(self, num_workers_to_kill):
     if num_workers_to_kill > len(self.children):
         self.logger.error(
             "Request to kill %d workers out of %d current workers", num_workers_to_kill, len(self.children)
         )
         return
     worker_pids = random.sample(self.children, num_workers_to_kill)
     for pid in worker_pids:
         safe_kill(pid)
     wait_for_pids(worker_pids, self.WAIT_FOR_KILL_TIME, self.logger)
Example #3
0
 def kill_workers(self, num_workers_to_kill):
     if num_workers_to_kill > len(self.children):
         self.logger.error(
             'Request to kill %d workers out of %d current workers',
             num_workers_to_kill,
             len(self.children)
         )
         return
     worker_pids = random.sample(self.children, num_workers_to_kill)
     for pid in worker_pids:
         safe_kill(pid)
     wait_for_pids(worker_pids, self.WAIT_FOR_KILL_TIME, self.logger)
Example #4
0
    def kill_all_workers(self):
        """Kill all workers and wait (synchronously) for them
        to exit"""
        # reset the signal handler so that we don't get interrupted
        # by SIGCHLDs
        signal.signal(signal.SIGCHLD, signal.SIG_DFL)
        waiting_pids = set()

        self.logger.debug('zygote requesting kill on %d pids', len(self.children))
        for pid in self.children:
            if safe_kill(pid, signal.SIGQUIT):
                waiting_pids.add(pid)
        wait_for_pids(waiting_pids, self.WAIT_FOR_KILL_TIME, self.logger)
        self.logger.debug('zygote done killing children, terminating')
        sys.exit(0)
Example #5
0
    def stop(self, signum=None, frame=None):
        """
        Stop the zygote master. Steps:
          * Ask all zygotes to kill and wait on their children
          * Wait for zygotes to exit
          * Kill anything left over if necessary
        """
        if self.stopped:
            return
        # kill all of the workers
        self.logger.info('stopping all zygotes and workers')
        pids = set()
        for zygote in self.zygote_collection:
            pids.add(zygote.pid)
            self.logger.debug('requesting shutdown on %d', zygote.pid)
            zygote.request_shut_down()

        self.logger.debug('setting self.stopped')
        self.stopped = True

        self.logger.debug(
            'master is stopping. will not try to update anymore.')
        signal.signal(signal.SIGHUP, signal.SIG_IGN)

        self.logger.debug('stopping io_loop.')
        if getattr(self, 'io_loop', None) is not None:
            self.io_loop.stop()

        self.logger.info('waiting for workers to exit before stoping master.')
        wait_for_pids(pids,
                      self.WAIT_FOR_KILL_TIME,
                      self.logger,
                      kill_pgroup=True)
        self.logger.info('all zygotes exited; good night')

        self.really_stop(0)