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