dabeaz / curio

Good Curio!
Other
4.04k stars 243 forks source link

aredis - ERROR #218

Closed wku closed 4 years ago

wku commented 7 years ago

Attempt to connect asynchronous redis Causes an error

import curio import aredis import asyncio

async def run(): print('run') redis = aredis.StrictRedis(host='127.0.0.1', port=6379, db=0) await redis.flushdb() await redis.set('bar', 'foo') bar = await redis.get('bar') print(bar)

if name == 'main':

So works

# loop = asyncio.get_event_loop()
# loop.run_until_complete(run())

#does not work
curio.run(run)

"""

..... File "/home/wku/anaconda3/lib/python3.6/asyncio/tasks.py", line 390, in _wait yield from waiter File "/home/wku/anaconda3/lib/python3.6/site-packages/curio/kernel.py", line 844, in _run_coro trapstrap[0] TypeError: '_asyncio.Future' object is not subscriptable ..... """

Fuyukai commented 7 years ago

Asyncio libraries are not compatible with curio without using the compatibility bridge.

wku commented 7 years ago

ok

from curio.bridge import AsyncioLoop import curio import aredis

async def aio_child(): print('') redis = aredis.StrictRedis(host='127.0.0.1', port=6379, db=0) await redis.flushdb() await redis.set('bar', 'foo') bar = await redis.get('bar') return bar

async def run(): async with AsyncioLoop() as loop: r = await loop.run_asyncio(aio_child) print (r.decode())

if name == 'main': curio.run(run)