Skip to content

Commit

Permalink
Fixed issue with invoking _close() on closed event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvildanov committed Nov 18, 2024
1 parent 00f5be4 commit ecf10fe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion redis/asyncio/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ def __del__(self, _warnings: Any = warnings):
_warnings.warn(
f"unclosed Connection {self!r}", ResourceWarning, source=self
)
self._close()

try:
asyncio.get_running_loop()
self._close()
except RuntimeError:
# No actions been taken if pool already closed.
pass

def _close(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion redis/asyncio/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(self, service_name, sentinel_manager, **kwargs):
self.is_master = kwargs.pop("is_master", True)
self.check_connection = kwargs.pop("check_connection", False)
super().__init__(**kwargs)
self.connection_kwargs["connection_pool"] = weakref.proxy(self)
self.connection_kwargs["connection_pool"] = self
self.service_name = service_name
self.sentinel_manager = sentinel_manager
self.master_address = None
Expand Down

0 comments on commit ecf10fe

Please sign in to comment.