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


Python asyncio.WindowsSelectorEventLoopPolicy方法代碼示例

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


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

示例1: _init_asyncio_patch

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import WindowsSelectorEventLoopPolicy [as 別名]
def _init_asyncio_patch():
    """
    Select compatible event loop for Tornado 5+.
    As of Python 3.8, the default event loop on Windows is `proactor`,
    however Tornado requires the old default "selector" event loop.
    As Tornado has decided to leave this to users to set, MkDocs needs
    to set it. See https://github.com/tornadoweb/tornado/issues/2608.
    """
    if sys.platform.startswith("win") and sys.version_info >= (3, 8):
        import asyncio
        try:
            from asyncio import WindowsSelectorEventLoopPolicy
        except ImportError:
            pass  # Can't assign a policy which doesn't exist.
        else:
            if not isinstance(asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy):
                asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy()) 
開發者ID:tableau,項目名稱:TabPy,代碼行數:19,代碼來源:app.py

示例2: event_loop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import WindowsSelectorEventLoopPolicy [as 別名]
def event_loop(request):
    """Overwrite `pytest_asyncio` eventloop to fix Windows issue.

    Default implementation causes `NotImplementedError` on Windows with
    Python 3.8, because they changed default eventloop in 3.8.

    NOTE: We do the same thing in the `example/settings.py` because it
    imports (and fails) before we have a chance to invoke this fixture.
    So, we could avoid adding this fixture, but I feel it is better to
    keep the proper solution here as well.

    """
    if sys.platform == "win32" and sys.version_info.minor >= 8:
        asyncio.set_event_loop_policy(
            asyncio.WindowsSelectorEventLoopPolicy()  # pylint: disable=no-member
        )
    loop = asyncio.get_event_loop_policy().new_event_loop()
    yield loop
    loop.close() 
開發者ID:datadvance,項目名稱:DjangoChannelsGraphqlWs,代碼行數:21,代碼來源:conftest.py

示例3: _init_asyncio_patch

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import WindowsSelectorEventLoopPolicy [as 別名]
def _init_asyncio_patch():
    """
    Select compatible event loop for Tornado 5+.

    As of Python 3.8, the default event loop on Windows is `proactor`,
    however Tornado requires the old default "selector" event loop.
    As Tornado has decided to leave this to users to set, MkDocs needs
    to set it. See https://github.com/tornadoweb/tornado/issues/2608.
    """
    if sys.platform.startswith("win") and sys.version_info >= (3, 8):
        import asyncio
        try:
            from asyncio import WindowsSelectorEventLoopPolicy
        except ImportError:
            pass  # Can't assign a policy which doesn't exist.
        else:
            if not isinstance(asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy):
                asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy()) 
開發者ID:mkdocs,項目名稱:mkdocs,代碼行數:20,代碼來源:serve.py

示例4: main

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import WindowsSelectorEventLoopPolicy [as 別名]
def main():
    # To avoid 'Event loop is closed' RuntimeError due to compatibility issue with aiohttp
    if sys.platform.startswith("win") and sys.version_info >= (3, 8):
        try:
            from asyncio import WindowsSelectorEventLoopPolicy
        except ImportError:
            pass
        else:
            if not isinstance(asyncio.get_event_loop_policy(), WindowsSelectorEventLoopPolicy):
                asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
    if sys.version_info >= (3, 7):
        asyncio.run(cli.main())
    else:
        loop = asyncio.get_event_loop()
        loop.run_until_complete(cli.main()) 
開發者ID:iojw,項目名稱:socialscan,代碼行數:17,代碼來源:__main__.py


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