From 2fc9eccfd5333eeef2fd36aad7b2869faa3a7449 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Fri, 7 Jul 2023 15:37:38 +0200 Subject: [PATCH] frappy_psi.sea: avoid multiple connections the _connect was sometimes started in parallel from startModules and the first call to doPoll. remove the first one, and protect the second one with a lock Change-Id: I079439e150efd5d005130cef475f6326f933ecbd --- frappy_psi/sea.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frappy_psi/sea.py b/frappy_psi/sea.py index bf294f7..fe907a4 100644 --- a/frappy_psi/sea.py +++ b/frappy_psi/sea.py @@ -138,7 +138,11 @@ class SeaClient(ProxyClient, Module): def doPoll(self): if not self.asynio and time.time() > self._last_connect + 10: - self._connect_thread = mkthread(self._connect, None) + with self._write_lock: + # make sure no more connect thread is running + if self._connect_thread and self._connect_thread.isAlive(): + return + self._connect_thread = mkthread(self._connect, None) def register_obj(self, module, obj): self.objects.add(obj) @@ -146,10 +150,6 @@ class SeaClient(ProxyClient, Module): self.path2param.setdefault(k, []).extend(v) self.register_callback(module.name, module.updateEvent) - def startModule(self, start_events): - super().startModule(start_events) - self._connect_thread = mkthread(self._connect, start_events.get_trigger()) - def _connect(self, started_callback): self._last_connect = time.time() if self._instance: