当前位置: 首页>>代码示例>>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;未经允许,请勿转载。