예제 #1
0
파일: base.py 프로젝트: vhoto-dev/gunicorn
    def __init__(self, age, ppid, sockets, app, timeout, cfg, log):
        """\
        This is called pre-fork so it shouldn't do anything to the
        current process. If there's a need to make process wide
        changes you'll want to do that in ``self.init_process()``.
        """
        self.age = age
        self.ppid = ppid
        self.sockets = sockets
        self.app = app
        self.timeout = timeout
        self.cfg = cfg
        self.booted = False

        self.nr = 0  # number of requests
        self.max_requests = cfg.max_requests or MAXSIZE
        self.alive = True
        self.log = log
        self.tmp = WorkerTmp(cfg)

        # instrumentation
        self.use_statsd = cfg.statsd_host is not None
        if self.use_statsd:
            self.log.info("Worker will send stats to {0}".format(cfg.statsd_host))
            self.last_nr = 0  # store nr at the last instrumentation call
            self.last_usr_t = 0  # store last user time from os.times()
            self.statsd = statsd(cfg.statsd_host, self.log)
예제 #2
0
    def setup(self, app):
        self.app = app
        self.cfg = app.cfg
        self.log = self.cfg.logger_class(app.cfg)

        # reopen files
        if 'GUNICORN_FD' in os.environ:
            self.log.reopen_files()

        self.worker_class = self.cfg.worker_class
        self.address = self.cfg.address
        self.num_workers = self.cfg.workers
        self.timeout = self.cfg.timeout
        self.proc_name = self.cfg.proc_name

        self.log.debug('Current configuration:\n{0}'.format(
            '\n'.join(
                '  {0}: {1}'.format(config, value.value)
                for config, value
                in sorted(self.cfg.settings.items(),
                          key=lambda setting: setting[1]))))

        if self.cfg.preload_app:
            self.app.wsgi()

        # instrumentation setup via statsD if needed
        self.use_statsd = self.cfg.statsd_host is not None
        if self.use_statsd:
            self.statsd = statsd(self.cfg.statsd_host, self.log)
            self.log.info("Arbiter will send stats to {0}".format(self.cfg.statsd_host))
        else:
            self.log.info("Arbiter will not send stats")