beremiz

merge

15 months ago, Edouard Tisserant
bdc21b1273f9
merge
--- a/Beremiz_service.py Fri Mar 14 14:30:05 2025 +0100
+++ b/Beremiz_service.py Mon Mar 17 15:28:19 2025 +0100
@@ -587,15 +587,13 @@
runtime.GetPLCObjectSingleton().AutoLoad(autostart)
-if havetwisted and havewx:
-
- waker_func = wx.CallAfter
-
+if havetwisted:
+ waker_func = reactor.callFromThread
+
# This orders ui loop to signal when ready on Stdout
waker_func(print,"UI thread started successfully.")
- # interleaved worker copes with wxreactor by delegating all asynchronous
- # calls to wx's mainloop
+ # interleaved worker delegates all calls to reactor
runtime.MainWorker.interleave(waker_func, reactor.stop, FirstWorkerJob)
try:
@@ -607,30 +605,19 @@
elif havewx:
+ waker_func = wx.CallAfter
+
+ # This orders ui loop to signal when ready on Stdout
+ waker_func(print,"UI thread started successfully.")
+
+ # interleaved worker delegates all calls to reactor
+ runtime.MainWorker.interleave(waker_func, app.ExitMainLoop, FirstWorkerJob)
+
try:
- app.MainLoop
+ app.MainLoop()
except KeyboardInterrupt:
pass
-elif havetwisted:
-
- ui_thread_started = Lock()
- ui_thread_started.acquire()
-
- reactor.callLater(0, ui_thread_started.release)
-
- ui_thread = Thread(
- target=partial(reactor.run, installSignalHandlers=False),
- name="UIThread")
- ui_thread.start()
-
- ui_thread_started.acquire()
- print("UI thread started successfully.")
- try:
- # blocking worker loop
- runtime.MainWorker.runloop(FirstWorkerJob)
- except KeyboardInterrupt:
- pass
else:
try:
# blocking worker loop
--- a/runtime/PLCObject.py Fri Mar 14 14:30:05 2025 +0100
+++ b/runtime/PLCObject.py Mon Mar 17 15:28:19 2025 +0100
@@ -566,14 +566,20 @@
self._fail(_("Problem starting PLC : error %d" % res))
@RunInMain
- def StopPLC(self):
+ def StopPLCLoop(self):
if self.PLCStatus == PlcStatus.Started:
self.LogMessage("PLC stopped")
self._stopPLC()
if self.TraceThread is not None:
self.TraceThread.join()
self.TraceThread = None
+ return True
+ return False
+ # Does not @RunInMain since python runtime Stop call must run in
+ # main thread, and StopPLC waits for it to complete
+ def StopPLC(self):
+ if self.StopPLCLoop():
# Wait for python runtime stop to complete
if self.PlcStopped.wait(timeout=5):
self.PLCStatus = PlcStatus.Stopped