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


Python tornado.ioloop方法代码示例

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


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

示例1: main

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def main():
    """
    Main function to start the webserver application and listen on the specified port.
    """
    tornado.options.parse_command_line()
    application = Application(tornado.options.options.domain,
                              tornado.options.options.salt,
                              tornado.options.options.redis_namespace,
                              tornado.options.options.redis_host,
                              int(tornado.options.options.redis_port),
                              tornado.options.options.redis_db,
                              tornado.options.options.redis_password,
                              int(tornado.options.options.ttl))
    if tornado.options.options.localhostonly:
        address = '127.0.0.1'
        logging.info('Listening to localhost only')
    else:
        address = ''
        logging.info('Listening to all addresses on all interfaces')
    application.listen(tornado.options.options.port, address=address, xheaders=True)
    tornado.ioloop.IOLoop.instance().start()


# Run main method if script is run from command line. 
开发者ID:nellessen,项目名称:tornado-shortener,代码行数:26,代码来源:app.py

示例2: _when_complete

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def _when_complete(self, result, callback):
        try:
            if result is None:
                callback()
            elif isinstance(result, Future):
                if result.done():
                    if result.result() is not None:
                        raise ValueError('Expected None, got %r' % result.result())
                    callback()
                else:
                    # Delayed import of IOLoop because it's not available
                    # on app engine
                    from tornado.ioloop import IOLoop
                    IOLoop.current().add_future(
                        result, functools.partial(self._when_complete,
                                                  callback=callback))
            else:
                raise ValueError("Expected Future or None, got %r" % result)
        except Exception as e:
            self._handle_request_exception(e) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:22,代码来源:web.py

示例3: start

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def start(cls):
        if cls.started:
            return

        # Set the flag to True *before* blocking on IOLoop.instance().start()
        cls.started = True

        """
        IOLoop.running() was removed as of Tornado 2.4; see for example
        https://groups.google.com/forum/#!topic/python-tornado/QLMzkpQBGOY
        Thus there is no correct way to check if the loop has already been
        launched. We may end up with two concurrently running loops in that
        unlucky case with all the expected consequences.
        """
        print("Press Ctrl+C to stop WebAgg server")
        sys.stdout.flush()
        try:
            tornado.ioloop.IOLoop.instance().start()
        except KeyboardInterrupt:
            print("Server is stopped")
            sys.stdout.flush()
        finally:
            cls.started = False 
开发者ID:miloharper,项目名称:neural-network-animation,代码行数:25,代码来源:backend_webagg.py

示例4: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def __init__(self, device_id, ioloop=None):
    super(DeviceInfo181Linux26, self).__init__()
    assert isinstance(device_id, DeviceIdMeta)
    self.ioloop = ioloop or tornado.ioloop.IOLoop.instance()
    self._device_id = device_id
    self.MemoryStatus = MemoryStatusLinux26()
    self.ProcessStatus = ProcessStatusLinux26(ioloop=ioloop)
    self.Unexport('FirstUseDate')
    self.Unexport(lists='Location')
    self.Unexport(objects='NetworkProperties')
    self.Unexport('ProvisioningCode')
    self.Unexport(objects='ProxierInfo')
    self.TemperatureStatus = temperature.TemperatureStatus()
    self.VendorLogFileList = {}
    self.VendorConfigFileList = {}
    self.SupportedDataModelList = {}
    self.ProcessorList = {}
    self.X_CATAWAMPUS_ORG_LedStatusList = {}
    self._next_led_number = 1 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:device_info.py

示例5: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def __init__(self, platform_config, port, ping_path,
               acs_url=None, get_parameter_key=None,
               start_periodic_session=None, ioloop=None,
               restrict_acs_hosts=None):
    self.ioloop = ioloop or tornado.ioloop.IOLoop.instance()
    self.restrict_acs_hosts = restrict_acs_hosts
    self.ValidateAcsUrl(acs_url)
    if platform_config:
      self.ValidateAcsUrl(platform_config.GetAcsUrl())
    self.acs_url = acs_url
    self.platform_config = platform_config
    self.port = port
    self.ping_path = ping_path
    self.get_parameter_key = get_parameter_key
    self.start_periodic_session = start_periodic_session
    self.my_ip = None
    self._periodic_callback = None
    self._start_periodic_timeout = None
    self.config_copy = None

    self.config = ServerParameters()
    self.ConfigurePeriodicInform() 
开发者ID:omererdem,项目名称:honeything,代码行数:24,代码来源:cpe_management_server.py

示例6: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def __init__(self, stateobj, transfer_complete_cb,
               download_dir=None, ioloop=None):
    """Download object.

    Args:
      stateobj: a PersistentObject to store state across reboots.
        This class requires that command_key and url attributes be present.
      transfer_complete_cb: function to send a TransferComplete message.
      ioloop: Tornado ioloop. Unit tests can pass in a mock.
    """
    self.stateobj = self._restore_dlstate(stateobj)
    self.transfer_complete_cb = transfer_complete_cb
    self.download_dir = download_path
    self.ioloop = ioloop or tornado.ioloop.IOLoop.instance()
    self.download = None
    self.downloaded_fileobj = None
    self.downloaded_file = None
    self.wait_handle = None
    # the delay_seconds started when we received the RPC, even if we have
    # downloaded other files and rebooted since then.
    if not hasattr(self.stateobj, 'wait_start_time'):
      self.stateobj.Update(wait_start_time=time.time()) 
开发者ID:omererdem,项目名称:honeything,代码行数:24,代码来源:download.py

示例7: cleanup

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def cleanup(self):
    """Attempt to stop all activity and clean up resources.

    Returns:
      False - successfully stopped and cleaned up
      string - the reason download cannot be safely cancelled right now.
    """
    dlstate = self.stateobj.dlstate
    if dlstate == self.INSTALLING:
      return 'Download is currently installing to flash'
    if dlstate == self.REBOOTING:
      return 'Download has been installed, awaiting reboot'
    if self.wait_handle:
      self.ioloop.remove_timeout(self.wait_handle)
      self.wait_handle = None
    if self.download:
      self.download.close()
      self.download = None
    self.stateobj.Delete() 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:download.py

示例8: _NewPingSession

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def _NewPingSession(self):
    if self.session:
      # $SPEC3 3.2.2 initiate at most one new session after this one closes.
      self.session.ping_received = True
      return

    # Rate limit how often new sessions can be started with ping to
    # once a minute
    current_time = helpers.monotime()
    elapsed_time = current_time - self.previous_ping_time
    allow_ping = (elapsed_time < 0 or
                  elapsed_time > self.rate_limit_seconds)
    if allow_ping:
      self.ping_timeout_pending = None
      self.previous_ping_time = current_time
      self._NewSession('6 CONNECTION REQUEST')
    elif not self.ping_timeout_pending:
      # Queue up a new session via tornado.
      callback_time = self.rate_limit_seconds - elapsed_time
      if callback_time < 1:
        callback_time = 1
      self.ping_timeout_pending = self.ioloop.add_timeout(
          datetime.timedelta(seconds=callback_time),
          self._NewTimeoutPingSession) 
开发者ID:omererdem,项目名称:honeything,代码行数:26,代码来源:http.py

示例9: _start_download

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def _start_download(self):
    #print 'starting (auth_header=%r)' % self.auth_header
    ht.logger.info('starting (auth_header=%r)' % self.auth_header)
    if not self.tempfile:
      self.tempfile = tempfile.NamedTemporaryFile(delete=True,
                                                  dir=self.download_dir)
    kwargs = dict(url=self.url,
                  request_timeout=3600.0,
                  streaming_callback=self.tempfile.write,
                  use_gzip=True, allow_ipv6=True,
                  user_agent='tr69-cpe-agent')
    if self.auth_header:
      kwargs.update(dict(headers=dict(Authorization=self.auth_header)))
    elif self.username and self.password:
      kwargs.update(dict(auth_username=self.username,
                         auth_password=self.password))
    req = tornado.httpclient.HTTPRequest(**kwargs)
    self.http_client = HTTPCLIENT(io_loop=self.ioloop)
    self.http_client.fetch(req, self._async_fetch_callback) 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:http_download.py

示例10: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def __init__(self, io_loop=None):
        if not io_loop:
            io_loop = tornado.ioloop.IOLoop.instance()
        self._io_loop = io_loop
        self._readers = {}  # map of reader objects to fd
        self._writers = {}  # map of writer objects to fd
        self._fds = {}  # a map of fd to a (reader, writer) tuple
        self._delayedCalls = {}
        PosixReactorBase.__init__(self)

        # IOLoop.start() bypasses some of the reactor initialization.
        # Fire off the necessary events if they weren't already triggered
        # by reactor.run().
        def start_if_necessary():
            if not self._started:
                self.fireSystemEvent('startup')
        self._io_loop.add_callback(start_if_necessary)

    # IReactorTime 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:twisted.py

示例11: __init__

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def __init__(self, zmq_url=None, host="127.0.0.1", port=None):
        self.host = host
        self.websocket_pool = set()
        self.app = self.make_app()
        self.ioloop = tornado.ioloop.IOLoop.current()

        if zmq_url is None:
            def f(port):
                return self.setup_zmq("{:s}://{:s}:{:d}".format(DEFAULT_ZMQ_METHOD, self.host, port))
            (self.zmq_socket, self.zmq_stream, self.zmq_url), _ = find_available_port(f, DEFAULT_ZMQ_PORT)
        else:
            self.zmq_socket, self.zmq_stream, self.zmq_url = self.setup_zmq(zmq_url)

        if port is None:
            _, self.fileserver_port = find_available_port(self.app.listen, DEFAULT_FILESERVER_PORT)
        else:
            self.app.listen(port)
            self.fileserver_port = port
        self.web_url = "http://{host}:{port}/static/".format(host=self.host, port=self.fileserver_port)

        self.tree = SceneTree() 
开发者ID:rdeits,项目名称:meshcat-python,代码行数:23,代码来源:zmqserver.py

示例12: init_one

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def init_one(self, ioloop, fetcher, processor,
                 result_worker=None, interactive=False):
        self.ioloop = ioloop
        self.fetcher = fetcher
        self.processor = processor
        self.result_worker = result_worker
        self.interactive = interactive
        self.running_task = 0 
开发者ID:binux,项目名称:pyspider,代码行数:10,代码来源:scheduler.py

示例13: send_task

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def send_task(self, task, force=True):
        if self.fetcher.http_client.free_size() <= 0:
            if force:
                self._send_buffer.appendleft(task)
            else:
                raise self.outqueue.Full
        self.ioloop.add_future(self.do_task(task), lambda x: x.result()) 
开发者ID:binux,项目名称:pyspider,代码行数:9,代码来源:scheduler.py

示例14: run

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def run(self):
        import tornado.ioloop
        tornado.ioloop.PeriodicCallback(self.run_once, 100,
                                        io_loop=self.ioloop).start()
        self.ioloop.start() 
开发者ID:binux,项目名称:pyspider,代码行数:7,代码来源:scheduler.py

示例15: quit

# 需要导入模块: import tornado [as 别名]
# 或者: from tornado import ioloop [as 别名]
def quit(self):
        self.ioloop.stop()
        logger.info("scheduler exiting...") 
开发者ID:binux,项目名称:pyspider,代码行数:5,代码来源:scheduler.py


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