asyncio.run is called inside a coroutine, where a loop is already running
What it finds
asyncio.run(main()) inside an async def: asyncio.run starts a new event loop and refuses to while one is running, so it raises RuntimeError when called from a coroutine. Inside one, the coroutine is awaited instead.
Calls in functions nested in the coroutine are left alone, since those may run in another thread.
From the rule's source, nested_event_loop.rs.
import asyncio async def handler(job): return asyncio.run(job())tx0 reports: asyncio.run inside a coroutine raises RuntimeError, since a loop is already running def main(job): return asyncio.run(job()) Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:nested-event-loop" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:nested-event-loop] reason="..."tx0 explain tx0/python:nested-event-loop shows the same in the terminal. Found a false positive? Report it.