--- a/runtime/PLCObject.py Thu May 28 14:06:23 2009 +0200
+++ b/runtime/PLCObject.py Thu May 28 17:29:19 2009 +0200
@@ -23,7 +23,7 @@
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from threading import Timer, Thread
+from threading import Timer, Thread, Lock import ctypes, os, commands, types, sys
@@ -53,6 +53,7 @@
self.workingdir = workingdir
self.PLCStatus = "Stopped"
self.PLClibraryHandle = None
+ self.PLClibraryLock = Lock() # Creates fake C funcs proxies
@@ -93,7 +94,12 @@
self._startPLC.restype = ctypes.c_int
self._startPLC.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)]
- self._stopPLC = self.PLClibraryHandle.stopPLC
+ self.PLClibraryLock.acquire() + self.PLClibraryHandle.stopPLC() + self.PLClibraryLock.release() + self._stopPLC = StopPLCLock self._stopPLC.restype = None
self._ResetDebugVariables = self.PLClibraryHandle.ResetDebugVariables
@@ -133,6 +139,7 @@
This is also called by __init__ to create dummy C func proxies
+ self.PLClibraryLock.acquire() # Forget all refs to library
self._startPLC = lambda:None
self._stopPLC = lambda:None
@@ -154,7 +161,7 @@
self._PLClibraryHandle = None
+ self.PLClibraryLock.release() def _DetectDirtyLibs(self):
@@ -251,7 +258,7 @@
self.evaluator(self.PrepareRuntimePy)
- while self.PLCStatus == "Started":
#print "_PythonIterator(", res, ")",
cmd = self._PythonIterator(res)
@@ -272,27 +279,19 @@
PLCprint("Problem %s PLC"%error)
self.PLCStatus = "Broken"
PLCprint("PythonThreadProc interrupted")
def StartPLC(self, debug=False):
- if self.CurrentPLCFilename is not None and self.PLCStatus == "Stopped":
+ if self.CurrentPLCFilename is not None: self.PythonThread = Thread(target=self.PythonThreadProc, args=[debug])
self.PythonThread.start()
if self.PLCStatus == "Started":
- self.PLCStatus = "Stopped"