summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2020-05-20 11:04:48 -0700
committerAndy McCurdy <andy@andymccurdy.com>2020-05-20 11:04:48 -0700
commitafb3b81dca308307a17409a0a97bb52b070716b8 (patch)
tree856e60aef5e5a850ebc09262ba915743efef3798
parent7c0a67a5cb4a20aea44c590837b0e79c9c09c510 (diff)
downloadredis-py-afb3b81dca308307a17409a0a97bb52b070716b8.tar.gz
Restore try/except in __del__ methods
Fixed #1339
-rw-r--r--CHANGES3
-rwxr-xr-xredis/client.py16
-rwxr-xr-xredis/connection.py15
3 files changed, 26 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index e087cf9..7da9b5c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+* (in development)
+ * Restore try/except clauses to __del__ methods. These will be removed
+ in 4.0 when more explicit resource management if enforced. #1339
* 3.5.2 (May 14, 2020)
* Tune the locking in ConnectionPool.get_connection so that the lock is
not held while waiting for the socket to establish and validate the
diff --git a/redis/client.py b/redis/client.py
index 6777959..3471895 100755
--- a/redis/client.py
+++ b/redis/client.py
@@ -3410,10 +3410,13 @@ class PubSub(object):
self.reset()
def __del__(self):
- # if this object went out of scope prior to shutting down
- # subscriptions, close the connection manually before
- # returning it to the connection pool
- self.reset()
+ try:
+ # if this object went out of scope prior to shutting down
+ # subscriptions, close the connection manually before
+ # returning it to the connection pool
+ self.reset()
+ except Exception:
+ pass
def reset(self):
if self.connection:
@@ -3762,7 +3765,10 @@ class Pipeline(Redis):
self.reset()
def __del__(self):
- self.reset()
+ try:
+ self.reset()
+ except Exception:
+ pass
def __len__(self):
return len(self.command_stack)
diff --git a/redis/connection.py b/redis/connection.py
index 9781b8c..5c8fd3c 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -296,7 +296,10 @@ class PythonParser(BaseParser):
self._buffer = None
def __del__(self):
- self.on_disconnect()
+ try:
+ self.on_disconnect()
+ except Exception:
+ pass
def on_connect(self, connection):
"Called when the socket connects"
@@ -374,7 +377,10 @@ class HiredisParser(BaseParser):
self._buffer = bytearray(socket_read_size)
def __del__(self):
- self.on_disconnect()
+ try:
+ self.on_disconnect()
+ except Exception:
+ pass
def on_connect(self, connection):
self._sock = connection._sock
@@ -534,7 +540,10 @@ class Connection(object):
return pieces
def __del__(self):
- self.disconnect()
+ try:
+ self.disconnect()
+ except Exception:
+ pass
def register_connect_callback(self, callback):
self._connect_callbacks.append(callback)