--- a/runtime/PLCObject.py Thu Jan 28 14:50:26 2021 +0000
+++ b/runtime/PLCObject.py Wed Mar 03 16:17:23 2021 +0100
@@ -388,8 +388,10 @@
self.PythonRuntimeCall("init", use_evaluator=False)
self.PythonThreadCondLock = Lock()
- self.PythonThreadCond = Condition(self.PythonThreadCondLock)
- self.PythonThreadCmd = "Wait"
+ self.PythonThreadCmdCond = Condition(self.PythonThreadCondLock) + self.PythonThreadAckCond = Condition(self.PythonThreadCondLock) + self.PythonThreadCmd = None + self.PythonThreadAck = None self.PythonThread = Thread(target=self.PythonThreadProc, name="PLCPythonThread")
self.PythonThread.start()
@@ -432,24 +434,43 @@
self.PythonThreadCondLock.acquire()
cmd = self.PythonThreadCmd
- self.PythonThreadCond.wait()
+ self.PythonThreadCmdCond.wait() cmd = self.PythonThreadCmd
- self.PythonThreadCmd = "Wait"
+ self.PythonThreadCmd = None self.PythonThreadCondLock.release()
+ # Ack once PreStart done, must be finished before StartPLC + self.PythonThreadAcknowledge(cmd) + # Ack Immediately, for responsiveness + self.PythonThreadAcknowledge(cmd) self.PythonRuntimeCall("start")
+ self.LogMessage("Python extensions started") self.PythonRuntimeCall("stop", reverse_order=True)
+ self.PythonThreadAcknowledge(cmd) + def PythonThreadAcknowledge(self, ack): + self.PythonThreadCondLock.acquire() + self.PythonThreadAck = ack + self.PythonThreadAckCond.notify() + self.PythonThreadCondLock.release() def PythonThreadCommand(self, cmd):
self.PythonThreadCondLock.acquire()
self.PythonThreadCmd = cmd
- self.PythonThreadCond.notify()
+ self.PythonThreadCmdCond.notify() + self.PythonThreadAckCond.wait() + ack = self.PythonThreadAck + self.PythonThreadAck = None self.PythonThreadCondLock.release()
@@ -473,13 +494,14 @@
self._fail(_("Problem starting PLC : can't load PLC"))
if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped:
+ self.PythonThreadCommand("PreStart") c_argv = ctypes.c_char_p * len(self.argv)
res = self._startPLC(len(self.argv), c_argv(*self.argv))
+ self.LogMessage("PLC started") self.PLCStatus = PlcStatus.Started
- self.PythonThreadCommand("Activate")
- self.LogMessage("PLC started")
+ self.PythonThreadCommand("Start") self._fail(_("Problem starting PLC : error %d" % res))