Skip to content

Uvloop

Fast implementation of asyncio event loop on top of libuv

Using uvloop

import asyncio
import uvloop

async def main():
    # Main entry-point.
    ...

uvloop.install()
asyncio.run(main())

좀 더 나은 버전

# -*- coding: utf-8 -*-

import asyncio
import warnings


def install_uvloop_driver() -> bool:
    """
    Install uvloop driver.

    .. warning::
        It should not be applied to be installed automatically.
        If you find a driver error, you should use the Python default settings.
    """

    try:
        import uvloop

        # Setup uvloop policy, so that every
        # asyncio.get_event_loop() will create an instance
        # of uvloop event loop.
        asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
    except ImportError:
        warnings.warn("Not found uvloop module")
        return False
    except BaseException as e:
        warnings.warn(f"uvloop installation failed: {e}")
        return False
    else:
        return True

Troubleshooting

get_child_watcher() NotImplementedError

/Users/your/.pyenv/versions/3.8.9/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py:616: in run_until_complete
    return future.result()
/Users/your/Project/recc/core/test/subprocess/test_async_subprocess.py:26: in test_default
    proc = await create_async_subprocess(
/Users/your/Project/recc/core/recc/subprocess/async_subprocess.py:159: in create_async_subprocess
    await proc.start()
/Users/your/Project/recc/core/recc/subprocess/async_subprocess.py:59: in start
    self._process = await create_subprocess_shell(
/Users/your/.pyenv/versions/3.8.9/Python.framework/Versions/3.8/lib/python3.8/asyncio/subprocess.py:216: in create_subprocess_shell
    transport, protocol = await loop.subprocess_shell(
/Users/your/.pyenv/versions/3.8.9/Python.framework/Versions/3.8/lib/python3.8/asyncio/base_events.py:1597: in subprocess_shell
    transport = await self._make_subprocess_transport(
/Users/your/.pyenv/versions/3.8.9/Python.framework/Versions/3.8/lib/python3.8/asyncio/unix_events.py:188: in _make_subprocess_transport
    with events.get_child_watcher() as watcher:
/Users/your/.pyenv/versions/3.8.9/Python.framework/Versions/3.8/lib/python3.8/asyncio/events.py:763: in get_child_watcher
    return get_event_loop_policy().get_child_watcher()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <uvloop.EventLoopPolicy object at 0x119751910>

    def get_child_watcher(self):
        "Get the watcher for child processes."
>       raise NotImplementedError
E       NotImplementedError

0.15.2 에서 아직 해결 안된듯 ...

See also

Favorite site