From 0740eb070443a9a262cc46434c6a1fae0edf5ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?= <francois.dekeersmaeker@uclouvain.be> Date: Tue, 20 May 2025 10:11:39 +0000 Subject: [PATCH] Fixed resource usage: close Fabric connection --- .../dns_unbound_cache_reader.py | 14 +++++++------- pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dns_unbound_cache_reader/dns_unbound_cache_reader.py b/dns_unbound_cache_reader/dns_unbound_cache_reader.py index 3d7056a..ae97337 100644 --- a/dns_unbound_cache_reader/dns_unbound_cache_reader.py +++ b/dns_unbound_cache_reader/dns_unbound_cache_reader.py @@ -87,13 +87,13 @@ def update_dns_table( ## Unbound runs on a remote host # SSH connection with remote host ssh_config = Config(overrides={"run": {"hide": True}}) - remote = Connection(host, config=ssh_config) - # Get the DNS cache - result = remote.run(cmd) - dns_cache = result.stdout.strip().split("\n") - # Free resources - del remote - del result + with Connection(host, config=ssh_config) as remote: + # Get the DNS cache + result = remote.run(cmd, warn=True) + if not result.failed: + dns_cache = result.stdout.strip().split("\n") + # Free resources + del result else: # Read DNS cache from file diff --git a/pyproject.toml b/pyproject.toml index b4e13ea..8930789 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "dns-unbound-cache-reader" -version = "0.3.0" +version = "0.4.0" description = "Read DNS cache from unbound" readme = "README.md" requires-python = ">=3.8" -- GitLab