Python asyncio.WindowsSelectorEventLoopPolicy() Examples
The following are 5
code examples of asyncio.WindowsSelectorEventLoopPolicy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
asyncio
, or try the search function
.
Example #1
Source File: conftest.py From DjangoChannelsGraphqlWs with MIT License | 7 votes |
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()
Example #2
Source File: app.py From TabPy with MIT License | 6 votes |
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())
Example #3
Source File: serve.py From mkdocs with BSD 2-Clause "Simplified" License | 6 votes |
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())
Example #4
Source File: serve.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
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())
Example #5
Source File: __main__.py From socialscan with Mozilla Public License 2.0 | 5 votes |
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())