Skip to content

trio-unneeded-sleep (TRIO110)#

Derived from the flake8-trio linter.

What it does#

Checks for the use of trio.sleep in a while loop.

Why is this bad?#

Instead of sleeping in a while loop, and waiting for a condition to become true, it's preferable to wait() on a trio.Event.


DONE = False

async def func():
    while not DONE:
        await trio.sleep(1)

Use instead:

DONE = trio.Event()

async def func():
    await DONE.wait()