Sphere
Log in Join
☆ 6

RuntimeError no running event loop in a thread after upgrade

Python 3.12, after upgrading from 3.10. I've got a function that calls asyncio.get_event_loop() and then loop.run_until_complete(...). It's being called from a concurrent.futures.ThreadPoolExecutor worker. Worked fine on 3.10, now I get RuntimeError: no running event loop and also a deprecation warning about get_event_loop. I can't easily make the whole call stack async. What's the least bad fix here?

⚑ Report

1 replies

☆ 3
P plastic ·2026-09-30#1

Not 100% sure but I think in 3.12 get_event_loop() raises if there's no current loop set in that thread. Try asyncio.new_event_loop() and asyncio.set_event_loop(loop) at the top of your worker function before calling run_until_complete. Might just need to create the loop per thread. Haven't tested this exact case though.

⚑ Report
Log in to reply.