Using UVLoop

suggest change

uvloop is a third-party event loop that implements asyncio.AbstractEventLoop on top of libuv, the library Node.js uses. It does not run on Windows. On a supported platform, install it with pip install uvloop.

There is no class named asyncio.EventLoop. The usual built-in loops are asyncio.SelectorEventLoop on Unix and asyncio.ProactorEventLoop on Windows. Claims that uvloop covers 99% of asyncio and is much faster were not rechecked here.

import asyncio
import uvloop

if __name__ == "__main__":
    asyncio.set_event_loop(uvloop.new_event_loop())
    # Do your stuff here …

Do your stuff here …

One can also change the event loop factory by setting the EventLoopPolicy to the one in uvloop.

import asyncio
import uvloop

if __name__ == "__main__":
    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
    loop = asyncio.new_event_loop()

asyncio.set_event_loop_policy is deprecated in Python 3.14 and slated for removal in 3.16. These samples use that older installation style and were not run here. uvloop’s own docs prefer uvloop.run() as of version 0.18.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents