'Main master loop.'

def run(self):

    self.start()
    util._setproctitle(('master    [%s]' % self.proc_name))
    try:
        self.manage_workers()
        while True:
            self.maybe_promote_master()
            sig = (self.SIG_QUEUE.pop(0) if self.SIG_QUEUE else None)
            if (sig is None):
                self.sleep()
                self.murder_workers()
                self.manage_workers()
                continue
            if (sig not in self.SIG_NAMES):
                self.log.info('Ignoring    unknown    signal:    %s', sig)
                continue
            signame = self.SIG_NAMES.get(sig)
            handler = getattr(self, ('handle_%s' % signame), None)
            if (not handler):
                self.log.error('Unhandled    signal:    %s', signame)
                continue
            self.log.info('Handling    signal:    %s', signame)
            handler()
            self.wakeup()
    except StopIteration:
        self.halt()
    except KeyboardInterrupt:
        self.halt()
    except HaltServer as inst:
        self.halt(reason=inst.reason, exit_status=inst.exit_status)
    except SystemExit:
        raise
    except Exception:
        self.log.info('Unhandled    exception    in    main    loop', exc_info=True)
        self.stop(False)
        if (self.pidfile is not None):
            self.pidfile.unlink()
        sys.exit((-1))
