runtime/PLCObject.py
changeset 2586 b89484560a97
parent 2583 e172ab28d04e
child 2594 f1e182818434
equal deleted inserted replaced
2585:fc6f441582cb 2586:b89484560a97
   388         self.PythonThreadCondLock = Lock()
   388         self.PythonThreadCondLock = Lock()
   389         self.PythonThreadCond = Condition(self.PythonThreadCondLock)
   389         self.PythonThreadCond = Condition(self.PythonThreadCondLock)
   390         self.PythonThreadCmd = "Wait"
   390         self.PythonThreadCmd = "Wait"
   391         self.PythonThread = Thread(target=self.PythonThreadProc)
   391         self.PythonThread = Thread(target=self.PythonThreadProc)
   392         self.PythonThread.start()
   392         self.PythonThread.start()
   393 
       
   394 
   393 
   395     # used internaly
   394     # used internaly
   396     def PythonRuntimeCleanup(self):
   395     def PythonRuntimeCleanup(self):
   397         if self.python_runtime_vars is not None:
   396         if self.python_runtime_vars is not None:
   398             self.PythonThreadCommand("Finish")
   397             self.PythonThreadCommand("Finish")
   434             while cmd == "Wait":
   433             while cmd == "Wait":
   435                 self.PythonThreadCond.wait()
   434                 self.PythonThreadCond.wait()
   436                 cmd = self.PythonThreadCmd
   435                 cmd = self.PythonThreadCmd
   437                 self.PythonThreadCmd = "Wait"
   436                 self.PythonThreadCmd = "Wait"
   438             self.PythonThreadCondLock.release()
   437             self.PythonThreadCondLock.release()
   439             
   438 
   440             if cmd == "Activate" :
   439             if cmd == "Activate":
   441                 self.PythonRuntimeCall("start")
   440                 self.PythonRuntimeCall("start")
   442 
       
   443                 self.PythonThreadLoop()
   441                 self.PythonThreadLoop()
   444                 
       
   445                 self.PythonRuntimeCall("stop")
   442                 self.PythonRuntimeCall("stop")
   446             else:  # "Finish"
   443             else:  # "Finish"
   447                 break
   444                 break
   448 
   445 
   449     def PythonThreadCommand(self, cmd):
   446     def PythonThreadCommand(self, cmd):
   450         self.PythonThreadCondLock.acquire()
   447         self.PythonThreadCondLock.acquire()
   451         self.PythonThreadCmd = cmd 
   448         self.PythonThreadCmd = cmd
   452         self.PythonThreadCond.notify()
   449         self.PythonThreadCond.notify()
   453         self.PythonThreadCondLock.release()
   450         self.PythonThreadCondLock.release()
   454 
   451 
   455     @RunInMain
   452     @RunInMain
   456     def StartPLC(self):
   453     def StartPLC(self):