File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -207,6 +207,9 @@ def __repr__(self):
207
207
repr_args = "," .join ((f"{ k } ={ v } " for k , v in self .repr_pieces ()))
208
208
return f"{ self .__class__ .__name__ } <{ repr_args } >"
209
209
210
+ def __del__ (self ):
211
+ self ._close_socket ()
212
+
210
213
@abstractmethod
211
214
def repr_pieces (self ):
212
215
pass
@@ -377,6 +380,15 @@ async def disconnect(self, nowait: bool = False) -> None:
377
380
f"Timed out closing connection after { self .socket_connect_timeout } "
378
381
) from None
379
382
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.
387
+ """
388
+ if self ._writer :
389
+ if os .getpid () == self .pid :
390
+ self ._writer .close ()
391
+
380
392
async def _send_ping (self ):
381
393
"""Send PING, expect PONG in return"""
382
394
await self .send_command ("PING" , check_health = False )
You can’t perform that action at this time.
0 commit comments