Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with invoking _close() on closed event loop #3438

Merged
merged 11 commits into from
Dec 5, 2024
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
6 changes: 1 addition & 5 deletions redis/asyncio/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)

def __repr__(self):
pool = self.connection_pool
s = (
f"<{self.__class__.__module__}.{self.__class__.__name__}"
f"(service={pool.service_name}"
)
s = f"<{self.__class__.__module__}.{self.__class__.__name__}"
if self.host:
host_info = f",host={self.host},port={self.port}"
s += host_info
Expand Down
Loading