--- a/runtime/PLCObject.py Tue Apr 09 09:13:55 2019 +0200
+++ b/runtime/PLCObject.py Tue Apr 09 13:05:35 2019 +0200
@@ -42,6 +42,7 @@
from runtime.Stunnel import getPSKID
from runtime import PlcStatus
from runtime import MainWorker
+from runtime import default_evaluator if os.name in ("nt", "ce"):
dlopen = _ctypes.LoadLibrary
@@ -319,13 +320,16 @@
- def PythonRuntimeCall(self, methodname):
+ def PythonRuntimeCall(self, methodname, use_evaluator=True): 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, []):
- _res, exp = self.evaluator(method)
+ _res, exp = self.evaluator(method) + _res, exp = default_evaluator(method) self.LogMessage(0, '\n'.join(traceback.format_exception(*exp)))
@@ -379,6 +383,8 @@
self.LogMessage(0, traceback.format_exc())
+ self.PythonRuntimeCall("init", use_evaluator=False) self.PythonThreadCondLock = Lock()
self.PythonThreadCond = Condition(self.PythonThreadCondLock)
self.PythonThreadCmd = "Wait"
@@ -391,6 +397,7 @@
if self.python_runtime_vars is not None:
self.PythonThreadCommand("Finish")
+ self.PythonRuntimeCall("cleanup", use_evaluator=False) self.python_runtime_vars = None
@@ -421,9 +428,6 @@
self.LogMessage(1, ('PyEval@0x%x(Code="%s") Exception "%s"') % (FBID, cmd, str(e)))
def PythonThreadProc(self):
- print('self.PythonRuntimeCall("init")')
- self.PythonRuntimeCall("init")
self.PythonThreadCondLock.acquire()
cmd = self.PythonThreadCmd
@@ -434,7 +438,6 @@
self.PythonThreadCondLock.release()
- print('self.PythonRuntimeCall("start")')
self.PythonRuntimeCall("start")
@@ -443,8 +446,6 @@
- self.PythonRuntimeCall("cleanup")
def PythonThreadCommand(self, cmd):
self.PythonThreadCondLock.acquire()
self.PythonThreadCmd = cmd
--- a/runtime/__init__.py Tue Apr 09 09:13:55 2019 +0200
+++ b/runtime/__init__.py Tue Apr 09 13:05:35 2019 +0200
@@ -30,3 +30,13 @@
global _PLCObjectSingleton
from runtime.PLCObject import PLCObject # noqa # pylint: disable=wrong-import-position
_PLCObjectSingleton = PLCObject(*args, **kwargs)
+def default_evaluator(tocall, *args, **kwargs): + res = (tocall(*args, **kwargs), None) + res = (None, sys.exc_info())