Skip to content

Commit

Permalink
Remove unnecessary __del__ handlers
Browse files Browse the repository at this point in the history
There normally should be no logic attached to del.  Cleanly disconnecting network resources is not needed at that time.
  • Loading branch information
kristjanvalur committed May 8, 2023
1 parent f056118 commit a50cec5
Showing 1 changed file with 0 additions and 18 deletions.
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 a50cec5

Please sign in to comment.