{"record":{"id":"b4fffbd5e2062ba1","repo":"python/cpython","slug":"runner-run-cannot-be-called-from-a-running-event","errorCode":null,"errorMessage":"Runner.run() cannot be called from a running event loop","messagePattern":"Runner\\.run\\(\\) cannot be called from a running event loop","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/runners.py","lineNumber":92,"sourceCode":"            loop.run_until_complete(\n                loop.shutdown_default_executor(constants.THREAD_JOIN_TIMEOUT))\n        finally:\n            if self._set_event_loop:\n                events.set_event_loop(None)\n            loop.close()\n            self._loop = None\n            self._state = _State.CLOSED\n\n    def get_loop(self):\n        \"\"\"Return embedded event loop.\"\"\"\n        self._lazy_init()\n        return self._loop\n\n    def run(self, coro, *, context=None):\n        \"\"\"Run code in the embedded event loop.\"\"\"\n        if events._get_running_loop() is not None:\n            # fail fast with short traceback\n            raise RuntimeError(\n                \"Runner.run() cannot be called from a running event loop\")\n\n        self._lazy_init()\n\n        if not coroutines.iscoroutine(coro):\n            if inspect.isawaitable(coro):\n                async def _wrap_awaitable(awaitable):\n                    return await awaitable\n\n                coro = _wrap_awaitable(coro)\n            else:\n                raise TypeError('An asyncio.Future, a coroutine or an '\n                                'awaitable is required')\n\n        if context is None:\n            context = self._context\n\n        task = self._loop.create_task(coro, context=context)","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/runners.py#L74-L110","documentation":"Error \"Runner.run() cannot be called from a running event loop\" thrown in python/cpython.","triggerScenarios":"Raised when Runner.run() is called from within an already-running event loop.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}