python/cpython · error · RuntimeError
Runner.run() cannot be called from a running event loop
Error message
Runner.run() cannot be called from a running event loop
What it means
Error "Runner.run() cannot be called from a running event loop" thrown in python/cpython.
Source
Thrown at Lib/asyncio/runners.py:92
loop.run_until_complete(
loop.shutdown_default_executor(constants.THREAD_JOIN_TIMEOUT))
finally:
if self._set_event_loop:
events.set_event_loop(None)
loop.close()
self._loop = None
self._state = _State.CLOSED
def get_loop(self):
"""Return embedded event loop."""
self._lazy_init()
return self._loop
def run(self, coro, *, context=None):
"""Run code in the embedded event loop."""
if events._get_running_loop() is not None:
# fail fast with short traceback
raise RuntimeError(
"Runner.run() cannot be called from a running event loop")
self._lazy_init()
if not coroutines.iscoroutine(coro):
if inspect.isawaitable(coro):
async def _wrap_awaitable(awaitable):
return await awaitable
coro = _wrap_awaitable(coro)
else:
raise TypeError('An asyncio.Future, a coroutine or an '
'awaitable is required')
if context is None:
context = self._context
task = self._loop.create_task(coro, context=context)View on GitHub (pinned to bc6749cc3b)
Solutions
- Do not call Runner.run() from inside a running event loop; await the coroutine directly instead.
- Call Runner.run() only from synchronous top-level code.
When it happens
Trigger: Raised when Runner.run() is called from within an already-running event loop.
Common situations: See trigger scenarios.
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/b4fffbd5e2062ba1.
Report an issue: GitHub.