Closed OliverTED closed 4 years ago
trio-asyncio is currently semi-maintained at best, and hasn't been adapted to the last two Trio releases (nor the 3.8 Python release).
Feel free to submit patches. :-/
Good to know. Well I can wrap my fix together and submit a patch. It lets trio_asyncio run again on python 3.8. But honestly I do not know if the solutions is a good one.
@OliverTED Hello, could you share your workaround? It freaks me out these days.
Sure. Here is the code that worked for me (I tested this only on little and only on python 3.8):
import trio_asyncio
from trio_asyncio import *
from asyncio import events as _aio_event
# the following workaround is apparaently necessary in python 3.8
try:
_orig_run_get = _aio_event.get_running_loop
except AttributeError:
pass
else:
def _new_run_get():
return _aio_event._get_running_loop()
_aio_event.get_running_loop = _new_run_get
Not sure if related, but I had to put the following at the top of my first async function (called by trio_asyncio.run):
# noinspection PyProtectedMember
asyncio._set_running_loop(asyncio.get_event_loop())
@OliverTED Really sorry for the slow response. At the end of 2019, I'm a little busy, some from life, some from work. Your workaround works for my project too, Thank you very much.
Same problem with Python 3.7.5 when use aioredis==1.3.1. Code sample:
import aioredis
import trio_asyncio
from functools import partial
async def main():
create_redis_pool = partial(
aioredis.create_redis_pool,
address='...',
encoding='utf-8'
)
redis = await trio_asyncio.run_asyncio(create_redis_pool)
print('Redis connected')
trio_asyncio.run(main)
Got similar traceback:
File ".../aioredis/stream.py", line 23, in open_connection
transport, _ = await get_event_loop().create_connection(
RuntimeError: no running event loop
Workaround suggested above works fine. Thanks to @parity3 !
Can you please try the 0.11.0 release and tell us if it helps?
This error appears to be resolved in 0.11.0, so closing. Please feel free to reopen if your issue is indeed unresolved.
Hey there! I have problems calling asyncio code from trio using trio_asyncio in python 3.8.
The following example is almost identical to the one from the docs. It works in python 3.7, but fails in python 3.8. After adding the monkeypatching flagged by the 'if False', it also works in python 3.8. Am I doing something wrong?
Thanks!
Here is the error in python 3.8: