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

feat(python): makes RedisConnection's close method async, use aclose when possible #2559

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AIexanderDicke
Copy link

redis.asyncio.client.Redis.close has been deprecated in Version 5.0.1 of redis. Therefore, RedisConnection.close now uses redis.asyncio.client.Redis.aclose whenever possible. To ensure backwards compatibility, close is still used if aclose is not available.

More importantly, self.conn.aclose() will be awaited (resulting in RedisConnection.close needing to be async). In fact, this fixes RuntimeError: Event loop stopped before Future completed. errors I get in certain situations when trying to gracefully stop a worker by running worker.close().

"""
Close the flow instance.
"""
return self.redisConnection.close()
return await self.redisConnection.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to await if the result is a future if you are going to return it anyway? I wonder because in JS is not needed.

Copy link
Author

@AIexanderDicke AIexanderDicke May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment! I thought about it a little bit and I think the best solution is to get rid of the return statement completely. This way it is much clearer that you have to await the closing of the connection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure why it is clearer, for instance, is it possible that the user calls close without awaiting it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you see something like

async def foo():
    await bar()

it is immediately clear that you have to run await foo(). On the other hand, if you have a function

def foo():
   return bar()

it's not so clear in my opinion.

await future instead of returning it
@AIexanderDicke AIexanderDicke requested a review from manast May 18, 2024 07:59
@klaemo
Copy link
Contributor

klaemo commented Jun 18, 2024

Can this get merged so we get rid of the deprecation warning and proper async closing of workers?

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

Successfully merging this pull request may close these issues.

3 participants