Skip to content

mode.loop.gevent``

Enable gevent support for asyncio.

Deprecated and currently broken

This loop backend is unmaintained, has no test coverage, and does not presently work on any interpreter -- importing it raises ImportError: Cannot import 'Loop' from mode.loop._gevent_loop with current gevent releases, on GIL-enabled and free-threaded builds alike. See docs/free-threading.md for the diagnosis.

Use the aio (default) or uvloop backend instead. This module will be removed in a future major release.

Policy

Bases: EventLoopPolicy

Custom gevent event loop policy.

Source code in mode/loop/gevent.py
81
82
83
84
85
86
87
88
89
90
91
92
class Policy(asyncio_gevent.EventLoopPolicy):  # type: ignore
    """Custom gevent event loop policy."""

    _loop: Optional[asyncio.AbstractEventLoop] = None

    def get_event_loop(self) -> asyncio.AbstractEventLoop:
        # asyncio_gevent raises an error here current_thread() is not MainThread,
        # but gevent monkey patches current_thread, so it's not a good check.
        loop = self._loop
        if loop is None:
            loop = self._loop = self.new_event_loop()
        return cast(asyncio.AbstractEventLoop, loop)

Warning

Importing this module directly will set the global event loop. See faust.loop for more information.