nicolargo/glances · error · RuntimeError

AsyncIO event loop failed to start within timeout

Error message

AsyncIO event loop failed to start within timeout

What it means

The AsyncIO export helper starts a background thread that creates an asyncio event loop and signals readiness via an Event. This RuntimeError is raised in __init__ when the loop thread does not set _loop_ready within 10 seconds, meaning the background loop never became usable. Typical causes are a dead/blocked loop thread, an exception inside the thread before signaling, or severe thread/CPU starvation at startup.

Source

Thrown at glances/exports/export_asyncio.py:51

    """

    def __init__(self, config=None, args=None):
        """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:

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. Check stderr/logs for the companion error 'AsyncIO event loop creation failed' — the thread usually records why it never signaled ready.
  2. Retry initialization once; transient thread scheduling delays can exceed the 10s timeout on loaded machines.
  3. Increase available CPU/threads for the process (raise container CPU limits, avoid mass-export plugin loading at startup).
  4. Inspect export_asyncio.py's _run_event_loop to see where _loop_ready.set() happens and whether the loop creation raised; report a bug if the exception path bypasses signalling.
Defensive patterns

Strategy: retry

Validate before calling

from glances.exports.export_asyncio import GlancesAsyncExport
import inspect
src = inspect.getsource(GlancesAsyncExport)
assert '_loop_ready' in src  # sanity: helper API present

Try / catch

try:
    export = MyAsyncExport(...)
except RuntimeError as e:
    if 'event loop failed to start' in str(e):
        export = None  # degrade gracefully, retry once

Prevention

When it happens

Trigger: Instantiating an export class deriving from GlancesAsyncExport (e.g. export_mqtt or similar async exporters) on a heavily loaded system, in an interpreter where the loop thread crashed, or where _run_event_loop exited before calling _loop_ready.set(). Also seen in restricted environments (some containers/sandboxes) that block thread creation.

Common situations: Embedded runs, Docker containers with low CPU quota, exotic interpreters (PyPy/Windows forks), or when the daemon thread is killed as the process shuts down during export init.

Understand the failure class

Related errors


AI-assisted analysis of nicolargo/glances@a240d8dfb3 (2026-08-27). Data as JSON: /api/errors/07b8fe110ae0caf5. Report an issue: GitHub.