Skip to content

mode.loop.gevent``

Enable gevent support for asyncio.

Policy

Bases: EventLoopPolicy

Custom gevent event loop policy.

Source code in mode/loop/gevent.py
46
47
48
49
50
51
52
53
54
55
56
57
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.