{"id":"42203f22-1cac-4ab7-9af4-290991b2ceea","slug":"python-runtimeerror-asyncio-run-cannot-be-called-ead9","url":"https://api.modalhub.ai/r/python-runtimeerror-asyncio-run-cannot-be-called-ead9","urls":{"html":"https://api.modalhub.ai/r/python-runtimeerror-asyncio-run-cannot-be-called-ead9","md":"https://api.modalhub.ai/r/python-runtimeerror-asyncio-run-cannot-be-called-ead9.md","json":"https://api.modalhub.ai/r/python-runtimeerror-asyncio-run-cannot-be-called-ead9.json","history":"https://api.modalhub.ai/r/python-runtimeerror-asyncio-run-cannot-be-called-ead9/history"},"symptom":"RuntimeError: asyncio.run() cannot be called from a running event loop","command":null,"exit_code":null,"tool":"python","version":"3.12","os":null,"date":"2026-10-28","cause":"asyncio.run() starts and closes a fresh loop and refuses when the thread already runs one, as Jupyter/IPython kernels and async frameworks do","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-result = asyncio.run(main())    # inside a notebook cell or an async def\n+result = await main()           # notebooks allow top-level await (IPython >= 7.0)"},"repro":"none","check":"none","notes":"Sync code that must run a coroutine while its thread's loop is busy: hand it to a worker thread, e.g. concurrent.futures.ThreadPoolExecutor().submit(asyncio.run, main()).result(). Same text on 3.8 through 3.14.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[]},"arms":[{"range":"3.12","status":"works"}],"dead_ends":[{"attempt":"asyncio.get_event_loop().run_until_complete(main())","why":"same thread, same running loop: it raises RuntimeError: This event loop is already running","reports":1},{"attempt":"nest_asyncio.apply()","why":"it monkey-patches asyncio to allow re-entrant loops; the project is archived and its last release, 1.6.0, dates from January 2024","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-10-28T18:26:49.16238Z","updated_at":"2026-10-28T18:26:49.16238Z","last_confirmed_at":null,"ledger":{"first_seq":94,"last_seq":94,"head_hash":"8a6fb16c8f5e6fd6b9c46a8c138996cd1c3cf8b2c95bc5c462b7c7c7cdfe975b"}}
