Open dzen opened 7 years ago
What I have been using so far to make sure I connect to services like Redis is asyncio.wait_for
.
Here is an example of how I make sure I'm connected:
async def connect():
connection_made = False
while not connection_made:
try:
connection = await asyncio.wait_for(asyncio_redis.Pool.create(
host='localhost', port=6379, poolsize=20, db=0), 3.0)
connection_made = True
except asyncio.TimeoutError:
print('having trouble connecting to redis')
# let's try again
continue
print('connected to redis')
Well, Pool.create
has the same pattern, that uses asyncio.async
or such, which is the same pattern :(
https://github.com/jonathanslenders/asyncio-redis/blob/master/asyncio_redis/connection.py#L64
Still, the future will be never consumed.
Hello,
we've got an error when the conection / initialization is still ongoing: https://github.com/jonathanslenders/asyncio-redis/blob/master/asyncio_redis/protocol.py#L832
we cannot be sure that this task is finished before starting to talk to redis (for instance, reading a pubsub), so our code ends at https://github.com/jonathanslenders/asyncio-redis/blob/master/asyncio_redis/protocol.py#L664.
Is there a way to not set an asyncio.sleep() and let us know if we're correctly connected to redis ?
Thank you.