From d0394ed7d88c7458b2c2035d9ac8ed00031a4a55 Mon Sep 17 00:00:00 2001 From: nocturn9x Date: Thu, 22 Apr 2021 14:31:58 +0200 Subject: [PATCH] Added socket destructor to unregister the socket from the loop --- giambio/socket.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/giambio/socket.py b/giambio/socket.py index bc0c6df..cd163b8 100644 --- a/giambio/socket.py +++ b/giambio/socket.py @@ -79,6 +79,17 @@ class AsyncSocket: raise ResourceClosed("I/O operation on closed socket") await self.loop.connect_sock(self.sock, addr) + def __del__(self): + """ + Implements the destructor for the async socket, + notifying the event loop that the socket must not + be listened for anymore. This avoids the loop + blocking forever on trying to read from a socket + that's gone out of scope without being closed + """ + + self.loop.selector.unregister(self.sock) + async def __aenter__(self): return self