New submission from Antoine Pitrou <pit...@free.fr>: If you await a Future with another loop than a loop at instance creation (this is trivial to do accidentally when using threads), asyncio raises a RuntimeError. But if you use another part of the Future API, such as add_done_callback(), the situation isn't detected.
For example, this snippet will run indefinitely: import asyncio import threading fut = asyncio.Future() async def coro(loop): fut.add_done_callback(lambda _: loop.stop()) loop.call_later(1, fut.set_result, None) while True: await asyncio.sleep(100000) def run(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(coro(loop)) loop.close() t = threading.Thread(target=run) t.start() t.join() ---------- components: asyncio messages: 305662 nosy: giampaolo.rodola, haypo, pitrou, yselivanov priority: normal severity: normal status: open title: Protection against using a Future with another loop only works with await type: behavior versions: Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue31960> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com