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


Python process.task_id函数代码示例

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


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

示例1: start_game

def start_game():
    ''' Main entry point for the application '''
    cache_actions()
    sockets = netutil.bind_sockets(8888)
    #if process.task_id() == None:
    #    tornado.process.fork_processes(-1, max_restarts = 10)
    server = HTTPServer(application)
    server.add_sockets(sockets)
    io_loop = IOLoop.instance()
    session_manager = SessionManager.Instance()
    if process.task_id() == None:
        scoring = PeriodicCallback(scoring_round, application.settings['ticks'], io_loop = io_loop)
        session_clean_up = PeriodicCallback(session_manager.clean_up, application.settings['clean_up_timeout'], io_loop = io_loop)
        scoring.start()
        session_clean_up.start()
    try:
        for count in range(3, 0, -1):
            logging.info("The game will begin in ... %d" % (count,))
            sleep(1)
        logging.info("Good hunting!")
        io_loop.start()
    except KeyboardInterrupt:
        if process.task_id() == 0:
            print '\r[!] Shutdown Everything!'
            session_clean_up.stop()
            io_loop.stop()
开发者ID:xaelek,项目名称:RootTheBox,代码行数:26,代码来源:__init__.py

示例2: run

 def run(self):
     logger.debug("starting main loop")
     self.handler.bind(self.port, address=None, backlog=128)
     self.handler.start(self.nprocs)
     signal.signal(signal.SIGINT, self.signal_shutdown)
     signal.signal(signal.SIGTERM, self.signal_shutdown)
     IOLoop.current().handle_callback_exception(self.handle_exception)
     taskid = '0' if task_id() == None else task_id()
     logger.debug("starting task %s (pid %d)" % (taskid, os.getpid()))
     IOLoop.instance().start()
     logger.debug("stopping main loop")
开发者ID:msfrank,项目名称:terane-toolbox,代码行数:11,代码来源:server.py

示例3: main

def main():
    """ entry """
    try:
        conf = __import__('conf')
    except ImportError as e:
        app_log.critical("Unable to load site config. ({})".format(e))
        raise SystemExit()
    parse_command_line()

    if options.debug:
        app_log.setLevel(logging.DEBUG)

    if not options.debug:
        fork_processes(None)
    options.port += task_id() or 0

    if not os.path.isdir(conf.app_path):
        app_log.critical("{p} isn't accessible, maybe "
                         "create it?".format(p=conf.app_path))
        raise SystemExit()
    app_log.debug("Starting {name} on port {port}".format(name=conf.name,
                                                          port=options.port))
    # initialize the application
    tornado.httpserver.HTTPServer(Application(options,
                                              conf)).listen(options.port,
                                                            '0.0.0.0')
    ioloop = tornado.ioloop.IOLoop.instance()
    if options.debug:
        tornado.autoreload.start(ioloop)
    # enter the Tornado IO loop
    ioloop.start()
开发者ID:sarahjanesllc-labs,项目名称:brutus,代码行数:31,代码来源:cli.py

示例4: main

def main():
    options.parse_command_line()

    _port = options.options.port
    _process_num = options.options.process
    _debug_level = options.options.debug * 10

    process.fork_processes(_process_num, max_restarts=3)

    process_port = _port + process.task_id()
    process_debug = _process_num <= 1 and _debug_level < 30

    print('Service Running on %d ...' % process_port)

    app = web.Application((
        (r'/', views.base.IndexHandler),
        (r'/home', views.base.HomeHandler),
        (r'/auth/redirect', views.auth.OAuth2RedirectHandler),
        (r'/auth/revoke', views.auth.OAuth2RevokeHandler),
        (r'/auth/authorize', views.auth.OAuth2AuthorizeHandler),
        (r'/auth/info', views.auth.OAuth2InfoHandler),
        (r'/user/info', views.rest.UserInfoHandler),
        (r'/user/option', views.rest.UserOptionHandler),
        (r'/weibo/public', views.rest.WeiboPublicHandler),
        (r'/weibo/sync', views.rest.WeiboSyncHandler),
        (r'/weibo/query', views.rest.WeiboQueryHandler),
        (r'/weibo/redirect', views.rest.WeiboRedirectHandler),
        (r'/emotion/query', views.rest.EmotionQueryHandler),
    ), debug=process_debug, cookie_secret=setting.COOKIE_SECRET)
    app.listen(process_port, xheaders=True)

    loop = ioloop.IOLoop.instance()
    loop.start()
开发者ID:codeb2cc,项目名称:noweibo,代码行数:33,代码来源:main.py

示例5: _reload_on_update

def _reload_on_update(modify_times):
    global needs_to_reload
    if _reload_attempted:
        # We already tried to reload and it didn't work, so don't try again.
        return
    if process.task_id() is not None:
        # We're in a child process created by fork_processes.  If child
        # processes restarted themselves, they'd all restart and then
        # all call fork_processes again.
        return
    for module in list(sys.modules.values()):
        # Some modules play games with sys.modules (e.g. email/__init__.py
        # in the standard library), and occasionally this can cause strange
        # failures in getattr.  Just ignore anything that's not an ordinary
        # module.
        if not isinstance(module, types.ModuleType):
            continue
        path = getattr(module, "__file__", None)
        if not path:
            continue
        if path.endswith(".pyc") or path.endswith(".pyo"):
            path = path[:-1]

        result = _check_file(modify_times, module, path)
        if result is False:
            # If any files errored, we abort this attempt at reloading.
            return
        if result is True:
            # If any files had actual changes that import properly,
            # we'll plan to reload the next time we run with no files
            # erroring.
            needs_to_reload = True

    if needs_to_reload:
        _reload()
开发者ID:284928489,项目名称:zulip,代码行数:35,代码来源:autoreload.py

示例6: set_defaults

def set_defaults():
    # type: () -> None
    instance = task_id()
    if instance is None:
        instance = 0

    default_tags = {"instance": str(instance)}

    get_plugin_proxy().set_default_stats_tags(default_tags)
开发者ID:dropbox,项目名称:grouper,代码行数:9,代码来源:stats.py

示例7: tearDown

 def tearDown(self):
     if task_id() is not None:
         # We're in a child process, and probably got to this point
         # via an uncaught exception.  If we return now, both
         # processes will continue with the rest of the test suite.
         # Exit now so the parent process will restart the child
         # (since we don't have a clean way to signal failure to
         # the parent that won't restart)
         logging.error("aborting child process from tearDown")
         logging.shutdown()
         os._exit(1)
     super(ProcessTest, self).tearDown()
开发者ID:BillyWu,项目名称:tornado,代码行数:12,代码来源:process_test.py

示例8: run

    def run(self):
        if options.debug:
            app_log.setLevel(logging.DEBUG)

        if not options.debug:
            fork_processes(None)
        options.port += task_id() or 0

        app_log.debug("Starting %s on port %s" % (cfg.platform_name, options.port))
        # initialize the application
        tornado.httpserver.HTTPServer(Application(self.commons)).listen(options.port, '0.0.0.0')
        ioloop = tornado.ioloop.IOLoop.instance()
        if options.debug:
            tornado.autoreload.start(ioloop)
        # enter the Tornado IO loop
        ioloop.start()
开发者ID:battlemidget,项目名称:cage-cmf,代码行数:16,代码来源:interface.py

示例9: test_multi_process

 def test_multi_process(self):
     self.assertFalse(IOLoop.initialized())
     port = get_unused_port()
     def get_url(path):
         return "http://127.0.0.1:%d%s" % (port, path)
     sockets = bind_sockets(port, "127.0.0.1")
     # ensure that none of these processes live too long
     signal.alarm(5)  # master process
     try:
         id = fork_processes(3, max_restarts=3)
     except SystemExit, e:
         # if we exit cleanly from fork_processes, all the child processes
         # finished with status 0
         self.assertEqual(e.code, 0)
         self.assertTrue(task_id() is None)
         for sock in sockets: sock.close()
         signal.alarm(0)
         return
开发者ID:CoolCold,项目名称:tornado,代码行数:18,代码来源:process_test.py

示例10: __init__

    def __init__(self, entries, timeout, max_clients):
        assert entries

        task_id = process.task_id()

        if options.multi_processes == -1:
            process_num = 1
        elif options.multi_processes == 0:
            process_num = process.cpu_count()
        else:
            process_num = options.multi_processes

        self._io_loop = ioloop.IOLoop()
        self._client = httpclient.AsyncHTTPClient(self._io_loop, max_clients=max_clients)

        self.timeout = timeout
        self.max_clients = max_clients
        self.requests = dict([(self.get_request(e), e) for e in entries])
        self.partial_requests = self.requests.keys()[task_id::process_num]
        self.count = len(self.partial_requests)
开发者ID:WilliamRen,项目名称:tornado-benchmark,代码行数:20,代码来源:checker.py

示例11: main

def main():
    try:
        options.parse_command_line()
        port = options.options.port
        fork = options.options.fork

        setting['PROCESS'] = fork
        setting['PORT_GROUP'] = range(port, port + fork)
        process.fork_processes(fork, max_restarts=10)

        setting['PORT'] = port + process.task_id()

        app = web.Application(
            handlers=urls,
            **SETTINGS
        )

        app.listen(setting['PORT'], xheaders=True)
        loop = ioloop.IOLoop.instance()
        loop.start()
    except Exception, e:
        logger.error(traceback.format_exc(e))
开发者ID:ccxryan,项目名称:bupt-apm,代码行数:22,代码来源:start_heypj.py

示例12: _reload_on_update

def _reload_on_update(modify_times):
    if _reload_attempted:
        # We already tried to reload and it didn't work, so don't try again.
        return
    if process.task_id() is not None:
        # We're in a child process created by fork_processes.  If child
        # processes restarted themselves, they'd all restart and then
        # all call fork_processes again.
        return
    for module in sys.modules.values():
        # Some modules play games with sys.modules (e.g. email/__init__.py
        # in the standard library), and occasionally this can cause strange
        # failures in getattr.  Just ignore anything that's not an ordinary
        # module.
        if not isinstance(module, types.ModuleType): continue
        path = getattr(module, "__file__", None)
        if not path: continue
        if path.endswith(".pyc") or path.endswith(".pyo"):
            path = path[:-1]
        _check_file(modify_times, path)
    for path in _watched_files:
        _check_file(modify_times, path)
开发者ID:Akylas,项目名称:CouchPotatoServer,代码行数:22,代码来源:autoreload.py

示例13: tornado_bidder_run

def tornado_bidder_run():
    """runs httpapi bidder agent"""

    # bind tcp port to launch processes on requests
    sockets = netutil.bind_sockets(CONFIG_OBJ["Bidder"]["Port"])

    # fork working processes
    process.fork_processes(0)

    # Tornado app implementation
    app = Application([url(r"/", TornadoFixPriceBidAgentRequestHandler)])

    # start http servers and attach the web app to it
    server = httpserver.HTTPServer(app)
    server.add_sockets(sockets)

    # perform following actions only in the parent process
    process_counter = process.task_id()
    if process_counter == 0:
        # run dummy ad server
        adserver_win = Application([url(r"/", TornadoDummyRequestHandler)])
        winport = CONFIG_OBJ["Bidder"]["Win"]
        adserver_win.listen(winport)
        adserver_evt = Application([url(r"/", TornadoDummyRequestHandler)])
        evtport = CONFIG_OBJ["Bidder"]["Event"]
        adserver_evt.listen(evtport)

        # --instantiate budget pacer
        pacer = BudgetControl()
        pacer.start(CONFIG_OBJ)

        # add periodic event to call pacer
        PeriodicCallback(pacer.http_request, CONFIG_OBJ["Banker"]["Period"]).start()

    # main io loop. it will loop waiting for requests
    IOLoop.instance().start()
开发者ID:michellepan,项目名称:rtbkit,代码行数:36,代码来源:http_bid_agent_ex.py

示例14: sigterm_handler

def sigterm_handler(signum, frame):
    print >> sys.stderr, "%s: SIGTERM received. Exiting..." % \
                         task_id(process.task_id())
    sys.exit(0)
开发者ID:smugen,项目名称:epio-custom-web-process,代码行数:4,代码来源:server.py

示例15: hello

def hello():
    cid = task_id()
    cid = "#%s" % cid if cid != None else "MAIN"
    user_ip = request.environ.get("REMOTE_ADDR", "Unknown")
    print "%s: serving a request from %s" % (cid, user_ip)
    return "Hello %s! from %s" % (user_ip, cid)
开发者ID:smugen,项目名称:epio-custom-web-process,代码行数:6,代码来源:app.py


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