nicolargo/glances · error · RuntimeError
AsyncIO event loop creation failed: {self._loop_exception}
Error message
AsyncIO event loop creation failed: {self._loop_exception} What it means
When the background thread that creates the asyncio event loop fails (e.g. asyncio.new_event_loop() raises), the exception is stored in _loop_exception and re-raised as RuntimeError from __init__. The message embeds the original exception text, so it's a wrapper around the real cause.
Source
Thrown at glances/exports/export_asyncio.py:54
"""Init the AsyncIO export interface."""
super().__init__(config=config, args=args)
# AsyncIO event loop management
self.loop = None
self._loop_ready = threading.Event()
self._loop_exception = None
self._shutdown = False
# Start the background event loop thread
self._loop_thread = threading.Thread(target=self._run_event_loop, daemon=True)
self._loop_thread.start()
# Wait for the loop to be ready
if not self._loop_ready.wait(timeout=10):
raise RuntimeError("AsyncIO event loop failed to start within timeout")
if self._loop_exception:
raise RuntimeError(f"AsyncIO event loop creation failed: {self._loop_exception}")
if self.loop is None:
raise RuntimeError("AsyncIO event loop is None after initialization")
# Call child class AsyncIO initialization
future = asyncio.run_coroutine_threadsafe(self._async_init(), self.loop)
try:
future.result(timeout=10)
logger.debug(f"{self.export_name} AsyncIO export initialized successfully")
except Exception as e:
logger.warning(f"{self.export_name} AsyncIO initialization failed: {e}. Will retry in background.")
def _run_event_loop(self):
"""Run event loop in background thread."""
try:
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self._loop_ready.set()View on GitHub (pinned to a240d8dfb3)
Solutions
- Read the embedded exception text — it names the actual failure (e.g. 'too many file descriptors').
- Fix the root cause: raise fd limits (ulimit -n), remove conflicting monkeypatches, or upgrade Python.
- Disable the failing async export plugin in glances.conf if it's not needed.
Defensive patterns
Strategy: try-catch
Try / catch
try:
export = MyAsyncExport(...)
except RuntimeError as e:
if 'event loop creation failed' in str(e):
root_cause = str(e).split(':', 1)[-1] # embedded original exception
logger.error('async export loop failed: %s', root_cause) Prevention
- Raise fd limits (ulimit -n) in long-running exporters.
- Avoid mixing gevent/eventlet monkeypatching with Glances async exports.
- Read the embedded exception text before guessing; it names the real failure.
When it happens
Trigger: Anything making event loop creation fail inside _run_event_loop: ResourceWarning/ResourceError from too many open FDs, a broken selector implementation, or a monkeypatched/broken asyncio module. The stored exception is raised from the constructor of any async export right after _loop_ready.wait() succeeds (thread sets the event, then records the exception) or after timeout.
Common situations: Environments with fd exhaustion (ulimit -n), CI runners with restricted asyncio selectors, or conflicting asyncio polyfills (gevent/eventlet patches).
Related errors
AI-assisted analysis of nicolargo/glances@a240d8dfb3 (2026-08-27).
Data as JSON: /api/errors/f9ddb6bf2930f490.
Report an issue: GitHub.