← Back to team overview

yade-dev team mailing list archive

[svn] r1481 - in trunk: gui/py scripts

 

Author: eudoxos
Date: 2008-08-20 14:21:01 +0200 (Wed, 20 Aug 2008)
New Revision: 1481

Modified:
   trunk/gui/py/PythonUI.hpp
   trunk/gui/py/PythonUI_rc.py
   trunk/scripts/default-test.py
Log:
1. Fix catching all (including SystemExit) exceptions in python scripts. If nonInteractive or stopAfter, exit immediately, otherwise just print traceback and drop to the python shell. Reveals many unfunctional generators suddenly.


Modified: trunk/gui/py/PythonUI.hpp
===================================================================
--- trunk/gui/py/PythonUI.hpp	2008-08-20 11:33:36 UTC (rev 1480)
+++ trunk/gui/py/PythonUI.hpp	2008-08-20 12:21:01 UTC (rev 1481)
@@ -19,6 +19,7 @@
 		static PythonUI *self;
 		virtual int run(int argc, char *argv[]);
 		static string runScript;
+		// stopAfter and nonInteractive are almost identical, should be clarified/fixed
 		static bool stopAfter;
 		static bool nonInteractive;
 		static vector<string> scriptArgs;

Modified: trunk/gui/py/PythonUI_rc.py
===================================================================
--- trunk/gui/py/PythonUI_rc.py	2008-08-20 11:33:36 UTC (rev 1480)
+++ trunk/gui/py/PythonUI_rc.py	2008-08-20 12:21:01 UTC (rev 1481)
@@ -30,9 +30,11 @@
 	print "Running script "+runtime.script
 	# an exception from python would propagate to c++ unhandled and cause crash
 	try: execfile(runtime.script)
-	except: 
+	except SystemExit: raise # re-raise sys.exit
+	except:
 		import traceback
 		traceback.print_exc()
+		if(runtime.nonInteractive or runtime.stopAfter): sys.exit(1)
 if runtime.stopAfter: sys.exit(0)
 
 # run commands if requested from the command line
@@ -40,8 +42,6 @@
 #	print "Running commands from commandline: "+yadeRunCommands
 #	exec(yadeRunCommands)
 
-# this cannot be run directly, since importing * is allowed only at module level
-
 if runtime.nonInteractive:
 	import time;
 	while True: time.sleep(1)

Modified: trunk/scripts/default-test.py
===================================================================
--- trunk/scripts/default-test.py	2008-08-20 11:33:36 UTC (rev 1480)
+++ trunk/scripts/default-test.py	2008-08-20 12:21:01 UTC (rev 1481)
@@ -37,7 +37,7 @@
 	import subprocess,os,os.path,yade.runtime
 	f=open(pyCmdFile,'w'); f.write(cmd); f.close(); 
 	if os.path.exists(msgFile): os.remove(msgFile)
-	p=subprocess.Popen([yade.runtime.executable,'-N','PythonUI','--','-s',pyCmdFile],stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
+	p=subprocess.Popen([yade.runtime.executable,'-N','PythonUI','--','-n','-s',pyCmdFile],stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
 	pout=p.communicate()[0]
 	retval=p.wait()
 	if not quiet: print pout
@@ -62,12 +62,10 @@
 	ok1,msg1,out1=crashProofRun(runGenerator%(pp,params))
 	if not ok1:
 		reports.append([pp,'generator CRASH',out1]); summary.append([pp,'generator CRASH'])
-		continue
-	ok2,msg2,out2=crashProofRun(runSimul)
-	if not ok2:
-		reports.append([pp,'simulation CRASH',out2]); summary.append([pp,'simulation CRASH'])
-	else: 
-		summary.append([pp,'passed (%s)'%msg2])
+	else:
+		ok2,msg2,out2=crashProofRun(runSimul)
+		if not ok2: reports.append([pp,'simulation CRASH',out2]); summary.append([pp,'simulation CRASH'])
+		else: summary.append([pp,'passed (%s)'%msg2])
 	print summary[-1][0]+':',summary[-1][1]
 
 # delete temporaries