当前位置: 首页>>代码示例>>Python>>正文


Python uwsgi.register_signal函数代码示例

本文整理汇总了Python中uwsgi.register_signal函数的典型用法代码示例。如果您正苦于以下问题:Python register_signal函数的具体用法?Python register_signal怎么用?Python register_signal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了register_signal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, target_temp):
        self._target_temp = target_temp
        self._timestep = 0
        self._MIN_VALID_TEMP = -5.0
        self._MAX_VALID_TEMP = 30.0
        self._READING_TICK = 5
        self._DELTA_OVERSHOOT_TEMP = 2.0
        self._SSR_PIN = 11
        self._compressor_state = True
        self._sensors = {}
        self._sensors['000001efbab6'] = 'top'
        self._sensors['000001efd9ac'] = 'bottom'
        self._sensors['000001eff556'] = 'beer'
        self._sensor_readings = deque(
            maxlen=int(60/self._READING_TICK)*len(W1.get_available_sensors())
        )

        logging.config.dictConfig(app.config['LOG_CONFIG'])
        self.logger = logging.getLogger('agent')

        if not app.config['DEBUG']:
            GPIO.setmode(GPIO.BOARD)
            GPIO.setup(self._SSR_PIN, GPIO.OUT)
            uwsgi.register_signal(9000, 'worker', self.run)
            uwsgi.add_timer(9000, 5)
            atexit.register(lambda: self.cleanup())

        if app.config['LOG_DEBUG']:
            self.logger.setLevel(logging.DEBUG)
        else:
            self.logger.setLevel(logging.WARN)

        self.logger.info("Agent started")
开发者ID:Webrewthebestbeer1,项目名称:fridge,代码行数:33,代码来源:agent.py

示例2: __init__

    def __init__(self, conf):

        super(uWSGIMixin, self).__init__(conf)

        class Lock():

            def __enter__(self):
                uwsgi.lock()

            def __exit__(self, exc_type, exc_val, exc_tb):
                uwsgi.unlock()

        def spooler(args):
            try:
                self.mailer.sendmail(args["subject"].decode('utf-8'), args["body"].decode('utf-8'))
            except smtplib.SMTPConnectError:
                return uwsgi.SPOOL_RETRY
            else:
                return uwsgi.SPOOL_OK

        uwsgi.spooler = spooler

        self.lock = Lock()
        self.mailer = SMTP(conf)
        self.cache = uWSGICache

        timedelta = conf.getint("moderation", "purge-after")
        purge = lambda signum: self.db.comments.purge(timedelta)
        uwsgi.register_signal(1, "", purge)
        uwsgi.add_timer(1, timedelta)

        # run purge once
        purge(1)
开发者ID:morozd,项目名称:isso,代码行数:33,代码来源:core.py

示例3: init_env_and_config

def init_env_and_config(app):
    if not app.config['FLATPAGES_ROOT']:
        app.config['FLATPAGES_ROOT'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            '../content')
    if app.config['CONTENT_URL']:
        init_repo(app.config["FLATPAGES_ROOT"], app.config['CONTENT_URL'])
    else:
        if not os.path.isdir(app.config['FLATPAGES_ROOT']):
            os.mkdir(app.config['FLATPAGES_ROOT'])

    try:
        import uwsgi
    except ImportError:
        logger.info("uwsgi package not found, uwsgi_timer hasn't been set")
    else:
        def update_uwsgi(signum):
            flatpages_root = app.config["FLATPAGES_ROOT"]
            logger.debug("Udpating git repository at %s", flatpages_root)
            hasToReload = update_repo(flatpages_root)
            if hasToReload:
                logger.debug("Reloading flatpages…")
                uwsgi.reload()

        logger.debug("Registering repo update to uwsgi signal")
        uwsgi.register_signal(20, "", update_uwsgi)
        uwsgi.add_timer(20, 300)

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    if not app.config.get('SECRET_KEY'):
        if not app.debug:
            logger.warning('SECRET_KEY not set. Using default Key.')
        app.config['SECRET_KEY'] = "yIhswxbuDCvK8a6EDGihW6xjNognxtyO85SI"
开发者ID:gwTumm,项目名称:sipa,代码行数:34,代码来源:initialization.py

示例4: start

 def start(self, interval, now=False):
     signum = get_free_signal()
     uwsgi.register_signal(signum, '', self._handle_signal)
     uwsgi.add_timer(signum, interval)
     if now:
         try:
             self._handle_signal(signum)
         except Exception as e:
             print e
             pass
开发者ID:GaretJax,项目名称:docker-deployer,代码行数:10,代码来源:utils.py

示例5: __init__

 def __init__(self, path):
     try:
         import os
         import uwsgi
         signal = [signum for signum in range(0,256) if not uwsgi.signal_registered(signum)][0]
         uwsgi.register_signal(signal, '', uwsgi.reload)
         for path in [x[0] for x in os.walk(path)]:
             uwsgi.add_file_monitor(signal, path.decode(encoding='UTF-8'))
     except Exception as err:
         pass # Not running under uwsgi. The other supported alternative is gunicorn. 
开发者ID:sergiosgc,项目名称:ZeroMass.py,代码行数:10,代码来源:AutoReloader.py

示例6: initialize

def initialize(signal_number=DEFAULT_TIMER_SIGNAL_NUMBER,
               update_period_s=DEFAULT_UPDATE_PERIOD_S):
    """Initialize metrics, must be invoked at least once prior to invoking any
    other method."""
    global initialized
    if initialized:
        return
    initialized = True
    uwsgi.add_timer(signal_number, update_period_s)
    uwsgi.register_signal(signal_number, MULE, emit)
开发者ID:hjacobs,项目名称:uwsgi_metrics,代码行数:10,代码来源:metrics.py

示例7: __init__

    def __init__(self, conf):

        super(uWSGIMixin, self).__init__(conf)

        self.lock = multiprocessing.Lock()
        self.cache = uWSGICache

        timedelta = conf.getint("moderation", "purge-after")
        purge = lambda signum: self.db.comments.purge(timedelta)
        uwsgi.register_signal(1, "", purge)
        uwsgi.add_timer(1, timedelta)

        # run purge once
        purge(1)
开发者ID:kod3r,项目名称:isso,代码行数:14,代码来源:core.py

示例8: init_env_and_config

def init_env_and_config(app):
    # default configuration
    app.config.from_pyfile(os.path.realpath("sipa/default_config.py"))
    # if local config file exists, load everything into local space.
    if 'SIPA_CONFIG_FILE' not in os.environ:
        os.environ['SIPA_CONFIG_FILE'] = os.path.realpath("config.py")
    try:
        app.config.from_envvar('SIPA_CONFIG_FILE', silent=True)
    except IOError:
        logger.warning("SIPA_CONFIG_FILE not readable: %s",
                       os.environ['SIPA_CONFIG_FILE'])
    else:
        logger.info("Successfully read config file %s",
                    os.environ['SIPA_CONFIG_FILE'])

    app.config.update({
        name[len("SIPA_"):]: value for name, value in os.environ.items()
        if name.startswith("SIPA_")
    })
    if app.config['FLATPAGES_ROOT'] == "":
        app.config['FLATPAGES_ROOT'] = os.path.join(
            os.path.dirname(os.path.abspath(__file__)),
            '../content')
    if app.config['CONTENT_URL']:
        init_repo(app.config["FLATPAGES_ROOT"], app.config['CONTENT_URL'])
    else:
        if not os.path.isdir(app.config['FLATPAGES_ROOT']):
            os.mkdir(app.config['FLATPAGES_ROOT'])

    if os.getenv("SIPA_UWSGI", "False") == 'True':
        import uwsgi

        def update_uwsgi(signum):
            hasToReload = update_repo(app.config["FLATPAGES_ROOT"])
            if hasToReload:
                uwsgi.reload

        logger.info("Registering repo update to uwsgi_signal")
        uwsgi.register_signal(20, "", update_uwsgi)
        uwsgi.add_timer(20, 300)

    if not app.config['SECRET_KEY']:
        raise ValueError("SECRET_KEY must not be empty")
开发者ID:MarauderXtreme,项目名称:sipa,代码行数:43,代码来源:initialization.py

示例9: start_insert_timer

def start_insert_timer(app):
	global insert_timer_started
	if insert_timer_started:
		return False
	insert_timer_started = True

	interval = app.config["INSERT_INTERVAL"]

	if uwsgi:
		uwsgi.register_signal(131, "workers", insert_timer_tick)
		uwsgi.add_rb_timer(131, interval)
		return True
	else:
		import threading
		def insert_timer_tick_loop():
			while 1:
				sleep(interval)
				insert_timer_tick()

		thread = threading.Thread(target=insert_timer_tick_loop, name="insert timer")
		thread.setDaemon(True)
		thread.start()
		return True
开发者ID:akx,项目名称:mess,代码行数:23,代码来源:timer.py

示例10: init

def init(app):
    def update_commands(signal_id):
        log.debug('Updating commands...')
        from pajbot.models.command import CommandManager
        bot_commands = CommandManager(
                socket_manager=None,
                module_manager=ModuleManager(None).load(),
                bot=None).load(load_examples=True)
        app.bot_commands_list = bot_commands.parse_for_web()

        app.bot_commands_list.sort(key=lambda x: (x.id or -1, x.main_alias))
        del bot_commands

    update_commands(26)
    try:
        import uwsgi
        from uwsgidecorators import thread, timer
        uwsgi.register_signal(26, 'worker', update_commands)
        uwsgi.add_timer(26, 60 * 10)

        @thread
        @timer(5)
        def get_highlight_thumbnails(no_clue_what_this_does):
            from pajbot.web.models.thumbnail import StreamThumbnailWriter
            with DBManager.create_session_scope() as db_session:
                highlights = db_session.query(StreamChunkHighlight).filter_by(thumbnail=None).all()
                if len(highlights) > 0:
                    log.info('Writing {} thumbnails...'.format(len(highlights)))
                    StreamThumbnailWriter(app.bot_config['main']['streamer'], [h.id for h in highlights])
                    log.info('Done!')
                    for highlight in highlights:
                        highlight.thumbnail = True
    except ImportError:
        log.exception('Import error, disregard if debugging.')
        pass
    pass
开发者ID:SanderVDA,项目名称:pajbot,代码行数:36,代码来源:tasks.py

示例11: getattr

    return getattr(logging, request.args.get('level'))

def set_log_level(sig=None):
    'set log level from current request'
    logger = current_app.logger

    if sig is not None and sig != UWSGI_SIG_SET_LOG_LEVEL:
        logger.info('refusing to set log level on signal: %s', sig)
        return

    level = parse_log_level()
    level_name = logging.getLevelName(level)
    msg = 'Setting log level to: %s'

    logger.debug(msg, level_name)
    logger.info(msg, level_name)
    logger.warning(msg, level_name)

    logger.setLevel(level)

try:
    import uwsgi
    uwsgi.register_signal(UWSGI_SIG_SET_LOG_LEVEL, 'workers', set_log_level) 
except ImportError:
    pass


if __name__ == '__main__':
    app = create_app()
    app.run(debug=False)
开发者ID:saml,项目名称:flask_log_level_runtime,代码行数:30,代码来源:app.py

示例12: hello_signal2

    print "i am the signal %d" % num


def hello_signal2(num, payload):
    print "i am the signal %d with payload: %s" % (num, payload)


def hello_file(num, filename):
    print "file %s has been modified !!!" % filename


def hello_timer(num, secs):
    print "%s seconds elapsed" % secs

# uwsgi.register_signal(30, uwsgi.SIGNAL_KIND_WORKER, hello_signal)
uwsgi.register_signal(30, "workers", hello_signal)
uwsgi.register_signal(22, "worker", hello_signal2, "*** PAYLOAD FOO ***")

uwsgi.register_file_monitor(3, "/tmp", "workers", hello_file)
uwsgi.register_timer(26, 2, "worker", hello_timer)
uwsgi.register_timer(17, 4, "worker2", hello_timer)
uwsgi.register_timer(5, 8, "worker3", hello_timer)


def application(env, start_response):

    start_response('200 Ok', [('Content-Type', 'text/html')])

    # this will send a signal to the master that will report it to the first available worker
    uwsgi.signal(30)
    uwsgi.signal(22)
开发者ID:Algy,项目名称:uwsgi,代码行数:31,代码来源:signals.py

示例13: get_wsgi_application

"""
WSGI config for NewRaPo project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""

import os

import uwsgi
from app.blog_lab.proxy.method import get_proxy, check_proxy
from app.blog_lab.proxy.huiyuan import play

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "NewRaPo.settings.produce")

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

uwsgi.register_signal(82, "", get_proxy)
uwsgi.add_cron(82, 0, -1, -1, -1, -1)
uwsgi.register_signal(84, "", check_proxy)
uwsgi.add_cron(84, 30, -1, -1, -1, -1)
uwsgi.register_signal(86, "", play)
uwsgi.add_cron(86, 0, 8, -1, -1, -1)
开发者ID:dongguangming,项目名称:django-angularjs-blog,代码行数:27,代码来源:cron_task.py

示例14: return

                return ("200 OK", {"X-Accel-Redirect": img}, "OK")
            else:
                return ("404 Not Found", {}, "404")

        if pfx == "/c/":
            url = self.get_url(banner_id)
            if url:
                self.clk_cache[banner_id] += 1
                return ("302 OK", {"Location": url}, url)
            else:
                return ("404 Not Found", {}, "404")

    def __call__(self, environ, start_response):
        resp = self.serve(environ["PATH_INFO"])
        if resp:
            resp[1]["Content-Length"] = str(len(resp[2]))
            start_response(resp[0], resp[1].items())
            return resp[2]
        else:
            return self.next_application(environ, start_response)


def commit_banners(x):
    banner_server.commit()

from wsgiref.simple_server import demo_app
application = banner_server = BannerServer(demo_app)

uwsgi.register_signal(42, 'workers', commit_banners)
uwsgi.add_rb_timer(42, 5)
开发者ID:akx,项目名称:banny,代码行数:30,代码来源:banny.py

示例15: register_ipython_console

    def register_ipython_console(self, name):
        trigger = IPYTHON_CONSOLE_TRIGGER % name
        os.close(os.open(trigger, os.O_WRONLY|os.O_CREAT, 0666))

        uwsgi.register_signal(IPYTHON_CONSOLE_SIGNAL, 'mule', activate_ipython_console)
        uwsgi.add_file_monitor(IPYTHON_CONSOLE_SIGNAL, trigger)
开发者ID:omersaeed,项目名称:spire,代码行数:6,代码来源:uwsgi.py


注:本文中的uwsgi.register_signal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。