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


Python ioloop.stop方法代码示例

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


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

示例1: stop

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def stop(self):
        """Stop the I/O loop.

        If the event loop is not currently running, the next call to `start()`
        will return immediately.

        To use asynchronous methods from otherwise-synchronous code (such as
        unit tests), you can start and stop the event loop like this::

          ioloop = IOLoop()
          async_method(ioloop=ioloop, callback=ioloop.stop)
          ioloop.start()

        ``ioloop.start()`` will return after ``async_method`` has run
        its callback, whether that callback was invoked before or
        after ``ioloop.start``.

        Note that even after `stop` has been called, the `IOLoop` is not
        completely stopped until `IOLoop.start` has also returned.
        Some work that was scheduled before the call to `stop` may still
        be run before the `IOLoop` shuts down.
        """
        raise NotImplementedError() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:25,代码来源:ioloop.py

示例2: Start

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def Start(self, timeout=None):
    """Run the mainloop repetitively until the program is finished.

    "Finished" means one of three things: no event handlers remain (unlikely),
    the timeout expires, or someone calls ioloop.stop().

    Args:
      timeout: the time at which the loop will be forcibly stopped.  Mostly
        useful in unit tests.  None means no timeout; 0 means stop instantly.
    """
    tmo = None
    if timeout is not None:
      self.loop_timeout = tmo = self.ioloop.add_timeout(
          datetime.timedelta(seconds=timeout), self._TimedOut)
    try:
      self.ioloop.start()
    finally:
      if tmo:
        self.ioloop.remove_timeout(tmo)
        self.loop_timeout = None 
开发者ID:omererdem,项目名称:honeything,代码行数:22,代码来源:mainloop.py

示例3: RunOnce

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def RunOnce(self, timeout=None):
    """Run the mainloop for exactly one iteration.

    Processes all events that occur during that iteration, including
    timeouts.

    Args:
      timeout: same meaning as in Start().
    """
    # TODO(apenwarr): timeout is effectively always 0 for now.  Oops.
    r, w = os.pipe()
    try:
      os.write(w, 'x')
      self.ioloop.add_handler(r, lambda fd, events: self.ioloop.stop(),
                              self.ioloop.READ)
      self.Start(timeout)
    finally:
      os.close(r)
      os.close(w)
      self.ioloop.remove_handler(r) 
开发者ID:omererdem,项目名称:honeything,代码行数:22,代码来源:mainloop.py

示例4: _start_application

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def _start_application(self, application, port):
        # Note: No significant application logic should be executed before this point. The call to application.listen()
        # will raise an exception if another process is using the same port. We rely on this exception to force us to
        # exit if there are any port conflicts.
        try:
            # If SSL cert and key files are provided in configuration, ClusterRunner wil start with HTTPS protocol.
            # Otherwise ClusterRunner will start with HTTP protocol.
            server = HTTPServer(application, ssl_options=self._get_https_options())
            server.listen(port, '0.0.0.0')
        except OSError:
            self._logger.error('Could not start application on port {}. Is port already in use?'.format(port))
            sys.exit(1)

        ioloop = tornado.ioloop.IOLoop.instance()

        # add a teardown callback that will stop the tornado server
        stop_tornado_ioloop = functools.partial(ioloop.add_callback, callback=ioloop.stop)
        UnhandledExceptionHandler.singleton().add_teardown_callback(stop_tornado_ioloop)
        return ioloop 
开发者ID:box,项目名称:ClusterRunner,代码行数:21,代码来源:service_subcommand.py

示例5: shutdown

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def shutdown(ioloop, server):
    ''' 关闭server

    :param server: tornado.httpserver.HTTPServer
    '''
    logging.info(
        "HTTP interpreter service will shutdown in %ss...", 1)
    server.stop()

    deadline = time.time() + 1

    def stop_loop():
        ''' 尝试关闭loop
        '''
        now = time.time()
        if now < deadline and (ioloop._callbacks or ioloop._timeouts):
            ioloop.add_timeout(now + 1, stop_loop)
        else:
            # 处理完现有的 callback 和 timeout 后
            ioloop.stop()
            logging.info('Shutdown!')

    stop_loop() 
开发者ID:JK-River,项目名称:RobotAIEngine,代码行数:25,代码来源:init.py

示例6: close

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def close(self, all_fds=False):
        """Closes the `IOLoop`, freeing any resources used.

        If ``all_fds`` is true, all file descriptors registered on the
        IOLoop will be closed (not just the ones created by the
        `IOLoop` itself).

        Many applications will only use a single `IOLoop` that runs for the
        entire lifetime of the process.  In that case closing the `IOLoop`
        is not necessary since everything will be cleaned up when the
        process exits.  `IOLoop.close` is provided mainly for scenarios
        such as unit tests, which create and destroy a large number of
        ``IOLoops``.

        An `IOLoop` must be completely stopped before it can be closed.  This
        means that `IOLoop.stop()` must be called *and* `IOLoop.start()` must
        be allowed to return before attempting to call `IOLoop.close()`.
        Therefore the call to `close` will usually appear just after
        the call to `start` rather than near the call to `stop`.

        .. versionchanged:: 3.1
           If the `IOLoop` implementation supports non-integer objects
           for "file descriptors", those objects will have their
           ``close`` method when ``all_fds`` is true.
        """
        raise NotImplementedError() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:28,代码来源:ioloop.py

示例7: start

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def start(self):
        """Starts the I/O loop.

        The loop will run until one of the callbacks calls `stop()`, which
        will make the loop stop after the current event iteration completes.
        """
        raise NotImplementedError() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:ioloop.py

示例8: stop

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def stop(self):
        pass 
开发者ID:fangpenlin,项目名称:bugbuzz-python,代码行数:4,代码来源:__init__.py

示例9: __init__

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def __init__(self, pubnub, url, urllib_func=None,
                 callback=None, error=None, id=None, timeout=5):
        self.url = url
        self.id = id
        self.callback = callback
        self.error = error
        self.stop = False
        self._urllib_func = urllib_func
        self.timeout = timeout
        self.pubnub = pubnub 
开发者ID:fangpenlin,项目名称:bugbuzz-python,代码行数:12,代码来源:__init__.py

示例10: cancel

# 需要导入模块: from tornado import ioloop [as 别名]
# 或者: from tornado.ioloop import stop [as 别名]
def cancel(self):
        self.stop = True
        self.callback = None
        self.error = None 
开发者ID:fangpenlin,项目名称:bugbuzz-python,代码行数:6,代码来源:__init__.py

示例11: start

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

        """
        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.
        """
        ioloop = tornado.ioloop.IOLoop.instance()

        def shutdown():
            ioloop.stop()
            print("Server is stopped")
            sys.stdout.flush()
            cls.started = False

        @contextmanager
        def catch_sigint():
            old_handler = signal.signal(
                signal.SIGINT,
                lambda sig, frame: ioloop.add_callback_from_signal(shutdown))
            try:
                yield
            finally:
                signal.signal(signal.SIGINT, old_handler)

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

        print("Press Ctrl+C to stop WebAgg server")
        sys.stdout.flush()
        with catch_sigint():
            ioloop.start() 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:38,代码来源:backend_webagg.py


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