Skip to content

Commit

Permalink
Issue #2749: Remove unnecessary __del__ handlers (#2755)
Browse files Browse the repository at this point in the history
* Remove unnecessary __del__ handlers
There normally should be no logic attached to del.  Cleanly disconnecting network resources is not needed at that time.

* add CHANGES
  • Loading branch information
kristjanvalur authored May 28, 2023
1 parent 2d9b5ac commit db7b9dd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
18 changes: 0 additions & 18 deletions redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit db7b9dd

Please sign in to comment.