From d3430290b27d76016208e2094eeb64137912c6aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 8 May 2023 17:08:45 +0000 Subject: [PATCH 1/2] Remove unnecessary __del__ handlers There normally should be no logic attached to del. Cleanly disconnecting network resources is not needed at that time. --- redis/asyncio/connection.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/redis/asyncio/connection.py b/redis/asyncio/connection.py index 462673f2ed..4ba177ef26 100644 --- a/redis/asyncio/connection.py +++ b/redis/asyncio/connection.py @@ -181,12 +181,6 @@ def __init__(self, socket_read_size: int): self._read_size = socket_read_size self._connected = False - def __del__(self): - try: - self.on_disconnect() - except Exception: - pass - @classmethod def parse_error(cls, response: str) -> ResponseError: """Parse an error response""" @@ -570,18 +564,6 @@ def repr_pieces(self): pieces.append(("client_name", self.client_name)) return pieces - def __del__(self): - try: - if self.is_connected: - loop = asyncio.get_running_loop() - coro = self.disconnect() - if loop.is_running(): - loop.create_task(coro) - else: - loop.run_until_complete(coro) - except Exception: - pass - @property def is_connected(self): return self._reader is not None and self._writer is not None From 6f47cf6f93dd2884703bffdfb183ebf4c8f4c460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Mon, 8 May 2023 18:43:43 +0000 Subject: [PATCH 2/2] add CHANGES --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 1e03453cc3..7fd510bd12 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,4 @@ + * Fix #2749, remove unnecessary __del__ logic to close connections. * Fix #2754, adding a missing argument to SentinelManagedConnection * Fix `xadd` command to accept non-negative `maxlen` including 0 * Revert #2104, #2673, add `disconnect_on_error` option to `read_response()` (issues #2506, #2624)