python/cpython · error · RuntimeError
This event loop is already running
Error message
This event loop is already running
What it means
Error "This event loop is already running" thrown in python/cpython.
Source
Thrown at Lib/asyncio/base_events.py:637
f"its threads within {timeout} seconds.",
RuntimeWarning, stacklevel=2)
self._default_executor.shutdown(wait=False)
else:
thread.join()
def _do_shutdown(self, future):
try:
self._default_executor.shutdown(wait=True)
if not self.is_closed():
self.call_soon_threadsafe(futures._set_result_unless_cancelled,
future, None)
except Exception as ex:
if not self.is_closed() and not future.cancelled():
self.call_soon_threadsafe(future.set_exception, ex)
def _check_running(self):
if self.is_running():
raise RuntimeError('This event loop is already running')
if events._get_running_loop() is not None:
raise RuntimeError(
'Cannot run the event loop while another loop is running')
def _run_forever_setup(self):
"""Prepare the run loop to process events.
This method exists so that custom event loop subclasses (e.g., event loops
that integrate a GUI event loop with Python's event loop) have access to all the
loop setup logic.
"""
self._check_closed()
self._check_running()
self._set_coroutine_origin_tracking(self._debug)
self._old_agen_hooks = sys.get_asyncgen_hooks()
self._thread_id = threading.get_ident()
sys.set_asyncgen_hooks(View on GitHub (pinned to bc6749cc3b)
Solutions
- Do not call loop.run_forever() or run_until_complete() from within a running loop; use await or asyncio.create_task() instead.
- Use asyncio.run() only at the top level of your program.
When it happens
Trigger: Raised when loop.run_forever()/run_until_complete() is called on a loop that is already running.
Common situations: See trigger scenarios.
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/2b9e920358773204.
Report an issue: GitHub.