runtime/PLCObject.py
changeset 344 25b7b7f854bc
parent 339 6dbde4a0c31d
child 350 a3a5561bde1d
--- 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