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


Python Application.config方法代码示例

本文整理汇总了Python中tornado.web.Application.config方法的典型用法代码示例。如果您正苦于以下问题:Python Application.config方法的具体用法?Python Application.config怎么用?Python Application.config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.web.Application的用法示例。


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

示例1: run_server

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import config [as 别名]
def run_server (config):
  os.umask(022)
  options.logging = 'debug'
  
  if config['daemon']:
    options.log_file_prefix = config['log']
    
  enable_pretty_logging(options=options)
  
  dbObj = initialize_db(config['db'])
  config['Job'] = dbObj['JobModel']
  config['CancelJob'] = dbObj['CancelModel']
  config['File'] = dbObj['File']
  
  q = multiprocessing.Queue()
  config['q'] = q
  from .worker import Worker
  w = Worker(q, logging, config)
  w.start()
  
  from .handlers import MainHandler, StaticHandler
  app = Application([
    (r"/\S+/public/(.*)", StaticHandler, {'path': config['dir']}),
    (r"/", MainHandler)
  ])
  app.config = config
  app.listen(config['port'])
  if config['reload']:
    tornado.autoreload.start()
    
    class reload_hook (object):
      def __init__ (self, w):
        self.w = w
      def run (self):
        self.w.terminate()
        
    tornado.autoreload.add_reload_hook(reload_hook(w).run)
    
  fh = open(config['pid'], 'w')
  fh.write('%d' % os.getpid())
  fh.close()
  
  def stopme (s, f):
    w.terminate()
    loop.stop()
    logging.info('Neutron Beam Stopped')
    
  loop = IOLoop.instance()
  signal.signal(signal.SIGTERM, stopme)
  
  loop.add_callback(started)
  try:
    loop.start()
    
  except (KeyboardInterrupt, SystemExit):
    w.terminate()
    logging.info('Neutron Beam Stopped')
    
  finally:
    try:
      raise
    
    except:
      pass
开发者ID:AnyBucket,项目名称:Neutron-Beam,代码行数:66,代码来源:run.py

示例2: server

# 需要导入模块: from tornado.web import Application [as 别名]
# 或者: from tornado.web.Application import config [as 别名]
def server(config):
    os.umask(022)

    fh = open(config["pid_file"], "w")
    fh.write("{}".format(os.getpid()))
    fh.close()

    options.logging = "debug"
    if not config["foreground"]:
        options.log_file_prefix = str(config["log_file"])

    enable_pretty_logging(options=options)

    app = Application(
        [
            # (r"/\S+/public/(.*)", StaticHandler, {'path': config['dir']}),
            (r"/setup/", SetupHandler),
            (r"/list/", ListHandler),
            (r"/file/get/", FileHandler),
            (r"/file/save/", FileSaveHandler),
            (r"/file/delete/", FileDeleteHandler),
            (r"/file/new/", FileNoobHandler),
            (r"/file/upload/", FileUploadHandler),
            (r"/file/rename/", FileRenameHandler),
            (r"/\S+/public/(.*)", StaticHandler, {"path": config["code_dir"]}),
        ]
    )

    app.config = config
    app.listen(config["port"])

    if config["auto_reload"]:
        tornado.autoreload.start()

        w = None

        class reload_hook(object):
            def __init__(self, w):
                self.w = w

            def run(self):
                pass
                # self.w.terminate()

        tornado.autoreload.add_reload_hook(reload_hook(w).run)

    def stopme(s, f):
        # w.terminate()
        loop.stop()
        logging.info("Neutron Beam Stopped")

    loop = IOLoop.instance()
    signal.signal(signal.SIGTERM, stopme)

    loop.add_callback(started)
    try:
        loop.start()

    except (KeyboardInterrupt, SystemExit):
        # w.terminate()
        logging.info("Neutron Beam Stopped")

    finally:
        try:
            raise

        except:
            pass
开发者ID:pizzapanther,项目名称:Super-Neutron-Drive,代码行数:70,代码来源:server.py


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