Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

way to ensure the connection is complete #105

Open
dzen opened this issue Jan 12, 2017 · 2 comments
Open

way to ensure the connection is complete #105

dzen opened this issue Jan 12, 2017 · 2 comments

Comments

@dzen
Copy link

dzen commented Jan 12, 2017

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.

@tgy
Copy link

tgy commented Jan 17, 2017

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')

@dzen
Copy link
Author

dzen commented Jan 17, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants