當前位置: 首頁>>代碼示例>>Python>>正文


Python asyncio.AsyncIOMainLoop方法代碼示例

本文整理匯總了Python中tornado.platform.asyncio.AsyncIOMainLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.AsyncIOMainLoop方法的具體用法?Python asyncio.AsyncIOMainLoop怎麽用?Python asyncio.AsyncIOMainLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.platform.asyncio的用法示例。


在下文中一共展示了asyncio.AsyncIOMainLoop方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: initialize

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AsyncIOMainLoop [as 別名]
def initialize(self, **kwargs):
        super(AsyncIOMainLoop, self).initialize(asyncio.get_event_loop(),
                                                close_loop=False, **kwargs) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:5,代碼來源:asyncio.py

示例2: current

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AsyncIOMainLoop [as 別名]
def current(instance: bool = True) -> Optional["IOLoop"]:
        """Returns the current thread's `IOLoop`.

        If an `IOLoop` is currently running or has been marked as
        current by `make_current`, returns that instance.  If there is
        no current `IOLoop` and ``instance`` is true, creates one.

        .. versionchanged:: 4.1
           Added ``instance`` argument to control the fallback to
           `IOLoop.instance()`.
        .. versionchanged:: 5.0
           On Python 3, control of the current `IOLoop` is delegated
           to `asyncio`, with this and other methods as pass-through accessors.
           The ``instance`` argument now controls whether an `IOLoop`
           is created automatically when there is none, instead of
           whether we fall back to `IOLoop.instance()` (which is now
           an alias for this method). ``instance=False`` is deprecated,
           since even if we do not create an `IOLoop`, this method
           may initialize the asyncio loop.
        """
        try:
            loop = asyncio.get_event_loop()
        except (RuntimeError, AssertionError):
            if not instance:
                return None
            raise
        try:
            return IOLoop._ioloop_for_asyncio[loop]
        except KeyError:
            if instance:
                from tornado.platform.asyncio import AsyncIOMainLoop

                current = AsyncIOMainLoop(make_current=True)  # type: Optional[IOLoop]
            else:
                current = None
        return current 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:38,代碼來源:ioloop.py

示例3: io_loop

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AsyncIOMainLoop [as 別名]
def io_loop(event_loop, request):
    """Same as pytest-tornado.io_loop, adapted for tornado 5"""
    io_loop = AsyncIOMainLoop()
    io_loop.make_current()
    assert io_loop.asyncio_loop is event_loop

    def _close():
        io_loop.clear_current()
        io_loop.close(all_fds=True)

    request.addfinalizer(_close)
    return io_loop 
開發者ID:jupyterhub,項目名稱:oauthenticator,代碼行數:14,代碼來源:conftest.py

示例4: io_loop

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AsyncIOMainLoop [as 別名]
def io_loop(event_loop, request):
    """Same as pytest-tornado.io_loop, but runs with pytest-asyncio"""
    io_loop = AsyncIOMainLoop()
    io_loop.make_current()
    assert io_loop.asyncio_loop is event_loop

    def _close():
        io_loop.clear_current()
        io_loop.close(all_fds=True)

    request.addfinalizer(_close)
    return io_loop 
開發者ID:jupyterhub,項目名稱:binderhub,代碼行數:14,代碼來源:conftest.py

示例5: use_asyncio

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AsyncIOMainLoop [as 別名]
def use_asyncio(reset = True):
    global Future, coroutine, IOStream, current_ioloop, is_reset
    if not reset and is_reset:
        return
    is_reset = reset

    from .asyncio import Future, coroutine, IOStream

    def asyncio_current_ioloop():
        global current_ioloop

        if IOLoop._instance.ioloop is None:
            try:
                from tornado.ioloop import IOLoop as TornadoIOLoop
                from tornado.platform.asyncio import AsyncIOMainLoop
                tornado_ioloop = TornadoIOLoop.current(False)
                if isinstance(tornado_ioloop, TornadoIOLoop) and not isinstance(tornado_ioloop, AsyncIOMainLoop):
                    return use_tornado(False)()
            except: pass

            from .asyncio import current_ioloop as _current_ioloop
            IOLoop._instance.ioloop = _current_ioloop()
            IOLoop._instance.call_soon = IOLoop._instance.ioloop.call_soon
            IOLoop._instance.call_at = IOLoop._instance.ioloop.call_at
            IOLoop._instance.call_later = IOLoop._instance.ioloop.call_later

            def cancel_timeout(timeout):
                timeout.cancel()
            IOLoop._instance.cancel_timeout = cancel_timeout
        current_ioloop = lambda: IOLoop._instance
        return IOLoop._instance

    current_ioloop = asyncio_current_ioloop
    return current_ioloop 
開發者ID:snower,項目名稱:TorMySQL,代碼行數:36,代碼來源:__init__.py

示例6: current

# 需要導入模塊: from tornado.platform import asyncio [as 別名]
# 或者: from tornado.platform.asyncio import AsyncIOMainLoop [as 別名]
def current(instance=True):
        """Returns the current thread's `IOLoop`.

        If an `IOLoop` is currently running or has been marked as
        current by `make_current`, returns that instance.  If there is
        no current `IOLoop` and ``instance`` is true, creates one.

        .. versionchanged:: 4.1
           Added ``instance`` argument to control the fallback to
           `IOLoop.instance()`.
        .. versionchanged:: 5.0
           On Python 3, control of the current `IOLoop` is delegated
           to `asyncio`, with this and other methods as pass-through accessors.
           The ``instance`` argument now controls whether an `IOLoop`
           is created automatically when there is none, instead of
           whether we fall back to `IOLoop.instance()` (which is now
           an alias for this method). ``instance=False`` is deprecated,
           since even if we do not create an `IOLoop`, this method
           may initialize the asyncio loop.
        """
        if asyncio is None:
            current = getattr(IOLoop._current, "instance", None)
            if current is None and instance:
                current = IOLoop()
                if IOLoop._current.instance is not current:
                    raise RuntimeError("new IOLoop did not become current")
        else:
            try:
                loop = asyncio.get_event_loop()
            except (RuntimeError, AssertionError):
                if not instance:
                    return None
                raise
            try:
                return IOLoop._ioloop_for_asyncio[loop]
            except KeyError:
                if instance:
                    from tornado.platform.asyncio import AsyncIOMainLoop
                    current = AsyncIOMainLoop(make_current=True)
                else:
                    current = None
        return current 
開發者ID:tp4a,項目名稱:teleport,代碼行數:44,代碼來源:ioloop.py


注:本文中的tornado.platform.asyncio.AsyncIOMainLoop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。