File tree 2 files changed +22
-2
lines changed
2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -546,6 +546,7 @@ def __del__(
546
546
_grl ().call_exception_handler (context )
547
547
except RuntimeError :
548
548
pass
549
+ self .connection ._close ()
549
550
550
551
async def aclose (self , close_connection_pool : Optional [bool ] = None ) -> None :
551
552
"""
Original file line number Diff line number Diff line change 5
5
import socket
6
6
import ssl
7
7
import sys
8
+ import warnings
8
9
import weakref
9
10
from abc import abstractmethod
10
11
from itertools import chain
@@ -204,9 +205,27 @@ def __init__(
204
205
raise ConnectionError ("protocol must be either 2 or 3" )
205
206
self .protocol = protocol
206
207
208
+ def __del__ (self , _warnings : Any = warnings ):
209
+ # For some reason, the individual streams don't get properly garbage
210
+ # collected and therefore produce no resource warnings. We add one
211
+ # here, in the same style as those from the stdlib.
212
+ if self ._writer :
213
+ _warnings .warn (
214
+ f"unclosed Connection { self !r} " , ResourceWarning , source = self
215
+ )
216
+ self ._close ()
217
+
218
+ def _close (self ):
219
+ """
220
+ Internal method to silently close the connection without waiting
221
+ """
222
+ if self ._writer :
223
+ self ._writer .close ()
224
+ self ._writer = self ._reader = None
225
+
207
226
def __repr__ (self ):
208
227
repr_args = "," .join ((f"{ k } ={ v } " for k , v in self .repr_pieces ()))
209
- return f"{ self .__class__ .__name__ } < { repr_args } >"
228
+ return f"< { self .__class__ .__module__ } . { self . __class__ . __name__ } ( { repr_args } ) >"
210
229
211
230
@abstractmethod
212
231
def repr_pieces (self ):
@@ -1017,7 +1036,7 @@ def __repr__(self):
1017
1036
1018
1037
def reset (self ):
1019
1038
self ._available_connections = []
1020
- self ._in_use_connections = set ()
1039
+ self ._in_use_connections = weakref . WeakSet ()
1021
1040
1022
1041
def can_get_connection (self ) -> bool :
1023
1042
"""Return True if a connection can be retrieved from the pool."""
You can’t perform that action at this time.
0 commit comments