Closed
Description
import trio
import trio_asyncio
from asyncio import Future, get_event_loop
@trio_asyncio.trio2aio
async def x():
f = Future()
get_event_loop().call_later(2, f.set_result, 1)
await f
async def main():
async with trio_asyncio.open_loop() as loop:
await x()
trio.run(main)
says:
RuntimeError: Task <Task pending coro=<x() running at test.py:9> cb=[run_future.<locals>.done_cb() at /Users/michael/.local/share/virtualenvs/mmm-ySqLnqEA/lib/python3.7/site-packages/trio_asyncio/util.py:23]> got Future <Future pending> attached to a different loop
This seems to be related to stuff now written in C. A naked Future()
call does not pick up the trio loop.
If in asyncio/futures.py I go to the end and change this code:
try:
import _asyncio
except ImportError:
pass
else:
# _CFuture is needed for tests.
Future = _CFuture = _asyncio.Future
to make sure _asyncio
is not imported, my program works.
Metadata
Metadata
Assignees
Labels
No labels