-
Notifications
You must be signed in to change notification settings - Fork 414
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
base: master
Are you sure you want to change the base?
Conversation
…close redis.asyncio.client.Redis
python/bullmq/flow_producer.py
Outdated
""" | ||
Close the flow instance. | ||
""" | ||
return self.redisConnection.close() | ||
return await self.redisConnection.close() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Can this get merged so we get rid of the deprecation warning and proper async closing of workers? |
redis.asyncio.client.Redis.close
has been deprecated in Version5.0.1
ofredis
. Therefore,RedisConnection.close
now usesredis.asyncio.client.Redis.aclose
whenever possible. To ensure backwards compatibility,close
is still used ifaclose
is not available.More importantly,
self.conn.aclose()
will be awaited (resulting inRedisConnection.close
needing to be async). In fact, this fixesRuntimeError: Event loop stopped before Future completed.
errors I get in certain situations when trying to gracefully stop a worker by runningworker.close()
.