PLCobject: Call "stop" and "cleanup" methods from python runtime files in reverse order compared to "init" and "start". svghmi
authorEdouard Tisserant
Wed, 18 Sep 2019 11:03:56 +0200
branchsvghmi
changeset 2778 cdf23b10b8f7
parent 2777 cdf6584953a0
child 2779 75c6a31caca6
PLCobject: Call "stop" and "cleanup" methods from python runtime files in reverse order compared to "init" and "start".
runtime/PLCObject.py
--- a/runtime/PLCObject.py	Mon Sep 16 13:45:04 2019 +0200
+++ b/runtime/PLCObject.py	Wed Sep 18 11:03:56 2019 +0200
@@ -319,12 +319,15 @@
 
         return False
 
-    def PythonRuntimeCall(self, methodname, use_evaluator=True):
+    def PythonRuntimeCall(self, methodname, use_evaluator=True, reverse_order=False):
         """
         Calls init, start, stop or cleanup method provided by
         runtime python files, loaded when new PLC uploaded
         """
-        for method in self.python_runtime_vars.get("_runtime_%s" % methodname, []):
+        methods = self.python_runtime_vars.get("_runtime_%s" % methodname, [])
+        if reverse_order:
+            methods = reversed(methods)
+        for method in methods:
             if use_evaluator:
                 _res, exp = self.evaluator(method)
             else:
@@ -395,7 +398,7 @@
         if self.python_runtime_vars is not None:
             self.PythonThreadCommand("Finish")
             self.PythonThread.join()
-            self.PythonRuntimeCall("cleanup", use_evaluator=False)
+            self.PythonRuntimeCall("cleanup", use_evaluator=False, reverse_order=True)
 
         self.python_runtime_vars = None
 
@@ -438,7 +441,7 @@
             if cmd == "Activate":
                 self.PythonRuntimeCall("start")
                 self.PythonThreadLoop()
-                self.PythonRuntimeCall("stop")
+                self.PythonRuntimeCall("stop", reverse_order=True)
             else:  # "Finish"
                 break