@@ -418,14 +418,16 @@ def __await__(self) -> Generator[Any, None, "RedisCluster"]:
418
418
419
419
_DEL_MESSAGE = "Unclosed RedisCluster client"
420
420
421
- def __del__ (self ) -> None :
421
+ def __del__ (
422
+ self , _warn : Any = warnings .warn , _grl : Any = asyncio .get_running_loop
423
+ ) -> None :
422
424
if hasattr (self , "_initialize" ) and not self ._initialize :
423
- warnings . warn (f"{ self ._DEL_MESSAGE } { self !r} " , ResourceWarning , source = self )
425
+ _warn (f"{ self ._DEL_MESSAGE } { self !r} " , ResourceWarning , source = self )
424
426
try :
425
427
context = {"client" : self , "message" : self ._DEL_MESSAGE }
426
- asyncio . get_running_loop ().call_exception_handler (context )
428
+ _grl ().call_exception_handler (context )
427
429
except RuntimeError :
428
- ...
430
+ pass
429
431
430
432
async def on_connect (self , connection : Connection ) -> None :
431
433
await connection .on_connect ()
@@ -954,17 +956,18 @@ def __eq__(self, obj: Any) -> bool:
954
956
955
957
_DEL_MESSAGE = "Unclosed ClusterNode object"
956
958
957
- def __del__ (self ) -> None :
959
+ def __del__ (
960
+ self , _warn : Any = warnings .warn , _grl : Any = asyncio .get_running_loop
961
+ ) -> None :
958
962
for connection in self ._connections :
959
963
if connection .is_connected :
960
- warnings .warn (
961
- f"{ self ._DEL_MESSAGE } { self !r} " , ResourceWarning , source = self
962
- )
964
+ _warn (f"{ self ._DEL_MESSAGE } { self !r} " , ResourceWarning , source = self )
965
+
963
966
try :
964
967
context = {"client" : self , "message" : self ._DEL_MESSAGE }
965
- asyncio . get_running_loop ().call_exception_handler (context )
968
+ _grl ().call_exception_handler (context )
966
969
except RuntimeError :
967
- ...
970
+ pass
968
971
break
969
972
970
973
async def disconnect (self ) -> None :
0 commit comments