From 4972c8bdcf38af40de6b561b30f6e29040c59504 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 16 Apr 2024 00:12:55 +0200 Subject: [PATCH] Unregister a Zeroconf instance if it already exists before publishing a backend service. `mdns` connection are another culprit for the increasing number of open files in the process. --- platypush/backend/__init__.py | 7 +++++++ platypush/plugins/zeroconf/__init__.py | 8 ++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/platypush/backend/__init__.py b/platypush/backend/__init__.py index 4835e15434..4f6ec73f43 100644 --- a/platypush/backend/__init__.py +++ b/platypush/backend/__init__.py @@ -402,6 +402,13 @@ class Backend(Thread, EventGenerator, ExtensionWithManifest): ) return + if self.zeroconf: + self.logger.info( + 'Zeroconf service already registered for %s, removing the previous instance', + self.__class__.__name__, + ) + self.unregister_service() + self.zeroconf = Zeroconf() srv_desc = { 'name': 'Platypush', diff --git a/platypush/plugins/zeroconf/__init__.py b/platypush/plugins/zeroconf/__init__.py index 51275cf1d4..be2c187910 100644 --- a/platypush/plugins/zeroconf/__init__.py +++ b/platypush/plugins/zeroconf/__init__.py @@ -46,9 +46,7 @@ class ZeroconfListener(ServiceListener): 'properties': { k.decode() if isinstance(k, bytes) - else k: v.decode() - if isinstance(v, bytes) - else v + else k: (v.decode() if isinstance(v, bytes) else v) for k, v in info.properties.items() }, 'server': info.server, @@ -166,9 +164,7 @@ class ZeroconfPlugin(Plugin): get_bus().post(evt) except queue.Empty: if not services: - self.logger.warning( - 'No such service discovered: {}'.format(service) - ) + self.logger.warning('No such service discovered: %s', service) finally: if browser: browser.cancel()