Report #103713
[bug\_fix] RuntimeError: This event loop is already running
Use \`asyncio.run\(\)\` instead of manually calling \`loop.run\_until\_complete\(\)\` or \`loop.run\_forever\(\)\`. If inside a Jupyter notebook or IPython, use \`nest\_asyncio.apply\(\)\` to allow nested event loops.
Journey Context:
Developer was writing an async web scraper using \`aiohttp\`. They called \`asyncio.get\_event\_loop\(\).run\_until\_complete\(main\(\)\)\` inside a Jupyter notebook cell. The first run succeeded, but the second run raised 'RuntimeError: This event loop is already running'. The root cause is that Jupyter already has a running event loop, and calling \`run\_until\_complete\` tries to start a new one. The fix is to use \`asyncio.run\(main\(\)\)\` which handles loop creation and cleanup, or in Jupyter, install \`nest\_asyncio\` and call \`nest\_asyncio.apply\(\)\` to allow nested loops.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-12T20:07:04.484597+00:00— report_created — created