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
This commit is contained in:
zolliker 2023-07-07 15:37:38 +02:00
parent ca57f46ed2
commit 2fc9eccfd5

View File

@ -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: