當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。