Skip to content

mode.loop

AsyncIO event loop implementations.

This contains a registry of different AsyncIO loop implementations to be used with Mode.

The choices available are:

aio default Normal asyncio event loop policy.

eventlet

Use eventlet as the event loop.

This uses aioeventlet and will apply the eventlet monkey-patches.

To enable execute the following as the first thing that happens when your program starts (e.g. add it as the top import of your entrypoint module):

import mode.loop
mode.loop.use('eventlet')

gevent

Use gevent as the event loop.

This uses aiogevent (+modifications) and will apply the gevent monkey-patches.

This choice enables you to run blocking Python code as if they have invisible async/await syntax around it (NOTE: C extensions are not usually gevent compatible).

To enable execute the following as the first thing that happens when your program starts (e.g. add it as the top import of your entrypoint module):

import mode.loop
mode.loop.use('gevent')

uvloop

Event loop using uvloop.

To enable execute the following as the first thing that happens when your program starts (e.g. add it as the top import of your entrypoint module):

import mode.loop
mode.loop.use('uvloop')

use(loop)

Specify the event loop to use as a string.

Loop must be one of: aio, eventlet, gevent, uvloop.

Source code in mode/loop/__init__.py
74
75
76
77
78
79
80
81
def use(loop: str) -> None:
    """Specify the event loop to use as a string.

    Loop must be one of: aio, eventlet, gevent, uvloop.
    """
    mod = LOOPS.get(loop, loop)
    if mod is not None:
        importlib.import_module(mod)