targets/plc_python.c
changeset 286 a2a8a52b0d4f
parent 281 3f0fc8de99b0
child 300 7f7912ae5ee8
--- a/targets/plc_python.c	Sun Jan 04 17:25:22 2009 +0100
+++ b/targets/plc_python.c	Sun Jan 04 17:29:12 2009 +0100
@@ -29,6 +29,7 @@
 #define PYTHON_LOCKED_BY_PYTHON 0
 #define PYTHON_LOCKED_BY_PLC 1
 #define PYTHON_MUSTWAKEUP 2
+#define PYTHON_FINISHED 4
  
 /* Each python_eval FunctionBlock have it own state */
 #define PYTHON_FB_FREE 0
@@ -55,6 +56,8 @@
 
 void __cleanup_python()
 {
+	PythonState = PYTHON_FINISHED;
+	UnBlockPythonCommands();
 }
 
 void __retrieve_python()
@@ -173,7 +176,10 @@
 	{
 		UnLockPython();
 		/* wait next FB to eval */
+		//printf("PythonIterator wait\n");
 		WaitPythonCommands();
+		/*emergency exit*/
+		if(PythonState & PYTHON_FINISHED) return NULL;
 		LockPython();
 	}
 	/* Mark block as processing */