flush-memcached: Explicitly close memcached connection.

Fixes warnings like “ResourceWarning: unclosed <socket.socket fd=3,
family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0,
laddr=('127.0.0.1', 33332), raddr=('127.0.0.1', 11211)>” with warnings
enabled.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-07-16 13:33:14 -07:00 committed by Tim Abbott
parent a0efc0ee76
commit c8eaceff21
1 changed files with 5 additions and 1 deletions

View File

@ -15,4 +15,8 @@ from zproject import settings
cache = settings.CACHES["default"]
assert isinstance(cache, dict) # for mypy
bmemcached.Client((cache["LOCATION"],), **cache["OPTIONS"]).flush_all()
client = bmemcached.Client((cache["LOCATION"],), **cache["OPTIONS"])
try:
client.flush_all()
finally:
client.disconnect_all()