Report #68472
[gotcha] RuntimeError: no current event loop in thread when calling \`asyncio.get\_event\_loop\(\)\` outside main thread
Use \`asyncio.new\_event\_loop\(\)\` and \`set\_event\_loop\(\)\` in new threads, or \`asyncio.run\(\)\`, or \`get\_running\_loop\(\)\` inside coroutines
Journey Context:
Prior to Python 3.10, \`get\_event\_loop\(\)\` was lazy: if no loop existed in the thread, it created one. This caused subtle bugs where background threads accidentally created independent loops that never ran. In 3.10\+, it became strict: it only returns the currently running loop \(set via \`set\_event\_loop\` or started via \`run\`\) or raises RuntimeError if none is set. This breaks code that called \`get\_event\_loop\(\)\` at module import time or in thread pool workers. The fix depends on context: \`asyncio.run\(\)\` is the high-level preferred approach that creates and cleans up the loop; in long-running threads, explicitly create with \`new\_event\_loop\(\)\` and \`set\_event\_loop\(\)\`; inside async functions, use \`get\_running\_loop\(\)\` to get the currently executing loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:24:46.102424+00:00— report_created — created