# HG changeset patch # User etisserant # Date 1232121558 -3600 # Node ID d7f8ffe1801797a9a61cf6fab5f099c5421566e9 # Parent 732e30ac8bf305c8a004dd1858da523ea2330f46 Enhanced the way "runtime.py" is executed, diff -r 732e30ac8bf3 -r d7f8ffe18017 runtime/PLCObject.py --- a/runtime/PLCObject.py Fri Jan 16 16:52:23 2009 +0100 +++ b/runtime/PLCObject.py Fri Jan 16 16:59:18 2009 +0100 @@ -178,22 +178,32 @@ return True return False - def ExecRuntimePy(self): + def PrepareRuntimePy(self): self.python_threads_vars = globals().copy() pyfile = os.path.join(self.workingdir, "runtime.py") if os.path.exists(pyfile): - # TODO handle exceptions in runtime.py - # pyfile may redefine _runtime_cleanup - # or even call _PythonThreadProc itself. - execfile(pyfile, self.python_threads_vars) + try: + # TODO handle exceptions in runtime.py + # pyfile may redefine _runtime_cleanup + # or even call _PythonThreadProc itself. + execfile(pyfile, self.python_threads_vars) + except: + PLCprint(traceback.format_exc()) + + def BeginRuntimePy(self): + runtime_begin = self.python_threads_vars.get("_runtime_begin",None) + if runtime_begin is not None: + runtime_begin() def FinishRuntimePy(self): - if self.python_threads_vars.get("_runtime_cleanup",None) is not None: - self.python_threads_vars["_runtime_cleanup"]() + runtime_cleanup = self.python_threads_vars.get("_runtime_cleanup",None) + if runtime_cleanup is not None: + runtime_cleanup() self.python_threads_vars = None def PythonThreadProc(self): PLCprint("PythonThreadProc started") + self.BeginRuntimePy() res,cmd = "None","None" while self.PLCStatus == "Started": #print "_PythonIterator(", res, ")", @@ -217,7 +227,7 @@ self._resumeDebug() self.PLCStatus = "Started" self.StatusChange() - self.ExecRuntimePy() + self.PrepareRuntimePy() self.PythonThread = Thread(target=self.PythonThreadProc) self.PythonThread.start() return True