Report #82082
[bug\_fix] RuntimeError: There is no current event loop in thread 'MainThread'
Use \`asyncio.run\(\)\` for the main entry point, or if in a thread, create a new loop with \`asyncio.new\_event\_loop\(\)\` and set it with \`asyncio.set\_event\_loop\(\)\`. Do not use \`get\_event\_loop\(\)\` in new code.
Journey Context:
Developer writes a Flask app and tries to use \`asyncio.run\(coroutine\(\)\)\` inside a route. It works the first request, but second request throws "RuntimeError: cannot run asyncio.run from a running loop" or "Event loop is closed". They try \`asyncio.get\_event\_loop\(\).run\_until\_complete\(\)\` instead, but get "There is no current event loop in thread 'Thread-1'". They realize Flask runs each request in a thread, and \`asyncio\` uses thread-local storage for the event loop. \`get\_event\_loop\(\)\` was deprecated in 3.10 and removed in 3.12; it only creates a loop in the main thread automatically. The fix is to use \`asyncio.run\(\)\` only at the top level, or in threads use \`asyncio.new\_event\_loop\(\)\` and \`loop.run\_until\_complete\(\)\`, or better, use \`asyncio.run\_coroutine\_threadsafe\(\)\` if communicating with a loop in another thread. This works because \`asyncio.run\(\)\` creates and closes a new event loop each time, safe for threads, whereas \`get\_event\_loop\(\)\` assumed main-thread auto-creation behavior that no longer exists.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:22:11.470865+00:00— report_created — created