Wait the debug thread has terminated before freeing PLC to avoid random segmentation fault.
Store working directory to globals copy, in order to be used in runtime.py.
--- a/runtime/PLCObject.py Mon May 18 07:43:03 2009 +0200
+++ b/runtime/PLCObject.py Mon May 18 07:47:24 2009 +0200
@@ -25,6 +25,7 @@
import Pyro.core as pyro
from threading import Timer, Thread
import ctypes, os, commands, types, sys
+import time
if os.name in ("nt", "ce"):
from _ctypes import LoadLibrary as dlopen
@@ -32,7 +33,7 @@
elif os.name == "posix":
from _ctypes import dlopen, dlclose
-import os,sys,traceback
+import traceback
lib_ext ={
"linux2":".so",
@@ -180,6 +181,7 @@
def PrepareRuntimePy(self):
self.python_threads_vars = globals().copy()
+ self.python_threads_vars["WorkingDir"] = self.workingdir
pyfile = os.path.join(self.workingdir, "runtime.py")
hmifile = os.path.join(self.workingdir, "hmi.py")
if os.path.exists(hmifile):
@@ -276,6 +278,8 @@
self.PLCStatus = "Stopped"
self.StatusChange()
self._stopPLC()
+ if self.PythonThread.isAlive():
+ self.PythonThread.join()
if self._FreePLC():
self.PLCStatus = "Dirty"
self.StatusChange()
@@ -414,6 +418,7 @@
else:
PLCprint("Debug error idx : %d, expected_idx %d, type : %s"%(idx.value, given_idx,typename.value))
res.append(None)
+ time.sleep(0.1)
self._FreeDebugData()
return tick, res
return -1, None
--- a/runtime/__init__.py Mon May 18 07:43:03 2009 +0200
+++ b/runtime/__init__.py Mon May 18 07:47:24 2009 +0200
@@ -2,5 +2,5 @@
import os
-from PLCObject import PLCObject
+from PLCObject import PLCObject, PLCprint
import ServicePublisher