Skip to content

Commit e183007

Browse files
committed
Remove the __del__ method again from asyincio.Connection
1 parent a80c64c commit e183007

File tree

2 files changed

+0
-52
lines changed

2 files changed

+0
-52
lines changed

redis/asyncio/connection.py

-23
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ def __repr__(self):
207207
repr_args = ",".join((f"{k}={v}" for k, v in self.repr_pieces()))
208208
return f"{self.__class__.__name__}<{repr_args}>"
209209

210-
def __del__(self):
211-
self._close_socket()
212-
213210
@abstractmethod
214211
def repr_pieces(self):
215212
pass
@@ -380,26 +377,6 @@ async def disconnect(self, nowait: bool = False) -> None:
380377
f"Timed out closing connection after {self.socket_connect_timeout}"
381378
) from None
382379

383-
def _close_socket(self):
384-
"""Close the socket directly. Used during garbage collection to
385-
make sure the underlying socket is released. This does not happen
386-
reliably when the stream is garbage collected. This is a safety
387-
precaution, correct use of the library should ensure that
388-
sockets are disconnected properly.
389-
"""
390-
# some test classes don't even have this
391-
writer = getattr(self, "_writer", None)
392-
if writer:
393-
if os.getpid() == self.pid:
394-
try:
395-
writer.close()
396-
except RuntimeError:
397-
# This may fail if the event loop is already closed,
398-
# even though this is not an async call. In this
399-
# case, just ignore the error, since it is during
400-
# exit anyway.
401-
pass
402-
403380
async def _send_ping(self):
404381
"""Send PING, expect PONG in return"""
405382
await self.send_command("PING", check_health=False)

tests/test_asyncio/test_connection.py

-29
Original file line numberDiff line numberDiff line change
@@ -320,32 +320,3 @@ async def get_redis_connection():
320320
assert r1.auto_close_connection_pool is False
321321
await r1.connection_pool.disconnect()
322322
await r1.close()
323-
324-
325-
@pytest.mark.onlynoncluster
326-
@pytest.mark.parametrize("from_url", (True, False))
327-
async def test_connection_socket_cleanup(request, from_url):
328-
"""Verify that connections are cleaned up when they
329-
are garbage collected
330-
"""
331-
if platform.python_implementation() != "CPython":
332-
pytest.skip("only works on CPython")
333-
url: str = request.config.getoption("--redis-url")
334-
url_args = parse_url(url)
335-
336-
async def get_redis_connection():
337-
if from_url:
338-
return Redis.from_url(url)
339-
return Redis(**url_args)
340-
341-
async def do_something(redis):
342-
await redis.incr("counter")
343-
await redis.close()
344-
345-
mock = Mock()
346-
with patch.object(AbstractConnection, "_close_socket", mock):
347-
r1 = await get_redis_connection()
348-
await do_something(r1)
349-
r1 = None
350-
351-
assert mock.call_count == 1

0 commit comments

Comments
 (0)