populate_db: Explicitly close memcached connection.

Fixes warnings like “ResourceWarning: unclosed <socket.socket fd=19,
family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0,
laddr=('127.0.0.1', 46244), 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:36:44 -07:00 committed by Tim Abbott
parent f3c67103cf
commit 8682ea1a64
1 changed files with 6 additions and 2 deletions

View File

@ -109,10 +109,14 @@ def clear_database() -> None:
# and; we only need to flush memcached if we're populating a
# database that would be used with it (i.e. zproject.dev_settings).
if default_cache["BACKEND"] == "zerver.lib.singleton_bmemcached.SingletonBMemcached":
bmemcached.Client(
memcached_client = bmemcached.Client(
(default_cache["LOCATION"],),
**default_cache["OPTIONS"],
).flush_all()
)
try:
memcached_client.flush_all()
finally:
memcached_client.disconnect_all()
model: Any = None # Hack because mypy doesn't know these are model classes