summaryrefslogtreecommitdiff
path: root/redis/connection.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-02-08 08:47:08 -0800
committerAndy McCurdy <andy@andymccurdy.com>2020-02-12 15:15:19 -0800
commit200e4dfc40ce0705ab6a3aca906e0a67884235e2 (patch)
tree9af739444bba0d538a474be3cac52b4c34306c13 /redis/connection.py
parentc8de2342d55bdd0cbd450148878d2789d8b4a7cd (diff)
downloadredis-py-200e4dfc40ce0705ab6a3aca906e0a67884235e2.tar.gz
Stop hiding errors that occur inside __del__ methods
If an exception occurs inside the __del__ method, it should be reported to the developer. Not doing so could hide bugs. Python automatically handles exceptions inside __del__ methods, for example: class A: def __del__(self): 1 / 0 A() print("after del") Results in the output: $ python3 ~/blah.py Exception ignored in: <function A.__del__ at 0x7fbbf2bbfc20> Traceback (most recent call last): File "/home/jon/test.py", line 3, in __del__ 1 / 0 ZeroDivisionError: division by zero after del From this example, we can see the bug was not hidden and the code after __del__ still executed. fixes #1281
Diffstat (limited to 'redis/connection.py')
-rwxr-xr-xredis/connection.py15
1 files changed, 3 insertions, 12 deletions
diff --git a/redis/connection.py b/redis/connection.py
index b5e3fb1..dbcf332 100755
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -288,10 +288,7 @@ class PythonParser(BaseParser):
self._buffer = None
def __del__(self):
- try:
- self.on_disconnect()
- except Exception:
- pass
+ self.on_disconnect()
def on_connect(self, connection):
"Called when the socket connects"
@@ -370,10 +367,7 @@ class HiredisParser(BaseParser):
self._buffer = bytearray(socket_read_size)
def __del__(self):
- try:
- self.on_disconnect()
- except Exception:
- pass
+ self.on_disconnect()
def on_connect(self, connection):
self._sock = connection._sock
@@ -533,10 +527,7 @@ class Connection(object):
return pieces
def __del__(self):
- try:
- self.disconnect()
- except Exception:
- pass
+ self.disconnect()
def register_connect_callback(self, callback):
self._connect_callbacks.append(callback)