From c8eaceff2152b83faa7e93a55b124aa76868c701 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 16 Jul 2024 13:33:14 -0700 Subject: [PATCH] flush-memcached: Explicitly close memcached connection. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes warnings like “ResourceWarning: unclosed ” with warnings enabled. Signed-off-by: Anders Kaseorg --- scripts/setup/flush-memcached | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/setup/flush-memcached b/scripts/setup/flush-memcached index 980045ca49..903c7bb281 100755 --- a/scripts/setup/flush-memcached +++ b/scripts/setup/flush-memcached @@ -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()