-
Notifications
You must be signed in to change notification settings - Fork 334
Warning caused by Redis.__del__()
#1115
Comments
Also having an issue with this, but the annoying thing on my end is that I've already closed the redis connection myself by explicitly calling (and awaiting) |
This was definitely a less-than-good idea (for which I take full responsibility) which we should probably update as suggested (change to a ResourceWarning if the connection is unclosed). Sorry for the pain here - I'll try to see if I've got time to make the change this week, or if anyone wants to make a quick contribution I'll look out for the PR and make sure to give it a timely review. |
@seandstewart - I made the change but I still get an error: sys:1: RuntimeWarning: coroutine 'Connection.disconnect' was never awaited (which is less errors than I was originally getting) Does |
Sounds like a generic error caused by calling the disconnect() method and then forgetting to await on it. You'd probably need to share some code that reproduces the issue, but I'm not seeing that one on our tests. The only other warning left in our tests is an unclosed socket which I can't seem to track down (but, I think it's internal to the Redis client). aio-libs/aiohttp-session#616 |
I enabled tracemalloc and it gave the line in question: sys:1: RuntimeWarning: coroutine 'Connection.disconnect' was never awaited I am using a pipeline (as the provided async context manager) but not sure if this is relevant or not |
yes I removed that code, and see another error. I can open another ticket for that separate issue if you like, but it all stems from the same thing - there isn't really a reliable way in python to have a library auto-clean up by calling coroutines. The end user needs to do that, but this library is littered with instances where it tries to auto clean up instead of calling out the user for not doing so. |
Oh wait, my mistake. That's a different class. So, the change needs to be copied to multiple classes then. |
I wouldn't mind taking a look at a new ticket with a proposal.
If anyone would like to make that PR, I'll look out for it (since I can't approve my own). |
Thank you for that one, seemed to have fixed my issues as well, though I also explicitly close the redis connection in a context object. |
This method calls
create_task()
, but then never awaits on that task. This raises a warning in Python, which fails CI for aiohttp-session. This happens even if we've closed the client explicitly.I was able to fix the warning by patching out the
__del__()
method: https://github.com/aio-libs/aiohttp-session/pull/616/files#diff-e52e4ddd58b7ef887ab03c04116e676f6280b824ab7469d5d3080e5cba4f2128R21Explicit is better than implicit, so I'd argue that this method doesn't need to exist, when you already have both a
.close()
method and support forasync with
. It's also misleading and a potential performance issue if an async client suddenly starts blocking on IO implicitly. Compare aiohttp's client, which merely raises an error:https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client.py#L284-L299
The text was updated successfully, but these errors were encountered: