Runtime: fix PLC not terminating when being Repaired (i.e purged).
--- a/Beremiz_service.py Fri Oct 21 17:52:45 2022 +0200
+++ b/Beremiz_service.py Fri Oct 21 18:33:06 2022 +0200
@@ -587,7 +587,7 @@
# interleaved worker copes with wxreactor by delegating all asynchronous
# calls to wx's mainloop
- runtime.MainWorker.interleave(waker_func, FirstWorkerJob)
+ runtime.MainWorker.interleave(waker_func, reactor.stop, FirstWorkerJob)
try:
reactor.run(installSignalHandlers=False)
--- a/runtime/PLCObject.py Fri Oct 21 17:52:45 2022 +0200
+++ b/runtime/PLCObject.py Fri Oct 21 18:33:06 2022 +0200
@@ -623,7 +623,7 @@
def RepairPLC(self):
self.PurgePLC()
- MainWorker.quit()
+ MainWorker.finish()
@RunInMain
def PurgePLC(self):
--- a/runtime/Worker.py Fri Oct 21 17:52:45 2022 +0200
+++ b/runtime/Worker.py Fri Oct 21 18:33:06 2022 +0200
@@ -52,6 +52,8 @@
self.free = Condition(self.mutex)
self.job = None
self.enabled = False
+ self.stopper = None
+ self.own_thread = None
def reraise(self, job):
"""
@@ -87,13 +89,14 @@
self.mutex.release()
- def interleave(self, waker, *args, **kwargs):
+ def interleave(self, waker, stopper, *args, **kwargs):
"""
as for twisted reactor's interleave, it passes all jobs to waker func
additionaly, it creates a new thread to wait for new job.
"""
self.feed = Condition(self.mutex)
self._threadID = _thread.get_ident()
+ self.stopper = stopper
def wakerfeedingloop():
self.mutex.acquire()
@@ -119,6 +122,8 @@
self.feed.notify()
self.done.notify()
self.mutex.release()
+ if self._finish:
+ break
waker(job_todo)
self.feed.wait()
@@ -189,3 +194,9 @@
self.todo.notify()
self.done.notify()
self.mutex.release()
+
+ def finish(self):
+ if self.own_thread is None:
+ self.quit()
+ if self.stopper is not None:
+ self.stopper()