{"record":{"id":"f9ddb6bf2930f490","repo":"nicolargo/glances","slug":"asyncio-event-loop-creation-failed-self-loop-ex","errorCode":null,"errorMessage":"AsyncIO event loop creation failed: {self._loop_exception}","messagePattern":"AsyncIO event loop creation failed: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"glances/exports/export_asyncio.py","lineNumber":54,"sourceCode":"        \"\"\"Init the AsyncIO export interface.\"\"\"\n        super().__init__(config=config, args=args)\n\n        # AsyncIO event loop management\n        self.loop = None\n        self._loop_ready = threading.Event()\n        self._loop_exception = None\n        self._shutdown = False\n\n        # Start the background event loop thread\n        self._loop_thread = threading.Thread(target=self._run_event_loop, daemon=True)\n        self._loop_thread.start()\n\n        # Wait for the loop to be ready\n        if not self._loop_ready.wait(timeout=10):\n            raise RuntimeError(\"AsyncIO event loop failed to start within timeout\")\n\n        if self._loop_exception:\n            raise RuntimeError(f\"AsyncIO event loop creation failed: {self._loop_exception}\")\n\n        if self.loop is None:\n            raise RuntimeError(\"AsyncIO event loop is None after initialization\")\n\n        # Call child class AsyncIO initialization\n        future = asyncio.run_coroutine_threadsafe(self._async_init(), self.loop)\n        try:\n            future.result(timeout=10)\n            logger.debug(f\"{self.export_name} AsyncIO export initialized successfully\")\n        except Exception as e:\n            logger.warning(f\"{self.export_name} AsyncIO initialization failed: {e}. Will retry in background.\")\n\n    def _run_event_loop(self):\n        \"\"\"Run event loop in background thread.\"\"\"\n        try:\n            self.loop = asyncio.new_event_loop()\n            asyncio.set_event_loop(self.loop)\n            self._loop_ready.set()","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/nicolargo/glances/blob/a240d8dfb3105a38b5964357ec21768594b0e83e/glances/exports/export_asyncio.py#L36-L72","documentation":"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.","triggerScenarios":"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.","commonSituations":"Environments with fd exhaustion (ulimit -n), CI runners with restricted asyncio selectors, or conflicting asyncio polyfills (gevent/eventlet patches).","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    export = MyAsyncExport(...)\nexcept RuntimeError as e:\n    if 'event loop creation failed' in str(e):\n        root_cause = str(e).split(':', 1)[-1]  # embedded original exception\n        logger.error('async export loop failed: %s', root_cause)","preventionTips":["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."],"tags":["asyncio","threading","export","wrapped-exception"],"backgroundTag":"asyncio-event-loop-startup-failure","analyzedSha":"a240d8dfb3105a38b5964357ec21768594b0e83e","analyzedAt":"2026-08-27T19:15:19.178Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}