Author: bugman Date: Wed Aug 10 22:40:24 2011 New Revision: 14328 URL: http://svn.gna.org/viewcvs/relax?rev=14328&view=rev Log: The interpreter thread no longer dies when an error occurs. This has been redesigned so that the error catching occurs within the infinite loop. Without this the user functions are completely useless after an error and do nothing. Modified: branches/gui_testing/gui/interpreter.py Modified: branches/gui_testing/gui/interpreter.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/interpreter.py?rev=14328&r1=14327&r2=14328&view=diff ============================================================================== --- branches/gui_testing/gui/interpreter.py (original) +++ branches/gui_testing/gui/interpreter.py Wed Aug 10 22:40:24 2011 @@ -30,6 +30,7 @@ import sys from threading import Thread from traceback import print_exc +import wx # relax module imports. from prompt import interpreter @@ -84,52 +85,49 @@ def run(self): """Execute the thread.""" - # Execute the user function, catching errors. - try: - # Loop until told to exit. - while not self._exit: - # Get the user function from the queue. - uf, args, kwds = self._queue.get() + # Loop until told to exit. + while not self._exit: + # Get the user function from the queue. + uf, args, kwds = self._queue.get() - # No user function. - if uf == None: - continue + # No user function. + if uf == None: + continue - # Execution lock. - status.exec_lock.acquire('gui', mode='interpreter thread') + # Execution lock. + status.exec_lock.acquire('gui', mode='interpreter thread') - # Make sure the lock is released if something goes wrong. - try: - # Handle the user function class. - if search('\.', uf): - # Split the user function. - uf_class, uf_fn = split(uf, '.') + # Execute the user function, catching errors. + try: + # Handle the user function class. + if search('\.', uf): + # Split the user function. + uf_class, uf_fn = split(uf, '.') - # Get the user function class. - obj = getattr(self._interpreter, uf_class) + # Get the user function class. + obj = getattr(self._interpreter, uf_class) - # Get the function. - fn = getattr(obj, uf_fn) + # Get the function. + fn = getattr(obj, uf_fn) - # Simple user function. - else: - fn = getattr(self._interpreter, uf) + # Simple user function. + else: + fn = getattr(self._interpreter, uf) - # Apply the user function. - apply(fn, args, kwds) + # Apply the user function. + apply(fn, args, kwds) - # Release the lock. - finally: - status.exec_lock.release() + # Catch all RelaxErrors. + except AllRelaxErrors, instance: + # Display a dialog with the error. + wx.CallAfter(gui_raise, instance, raise_flag=False) - # Catch all RelaxErrors. - except AllRelaxErrors, instance: - # Display a dialog with the error. - gui_raise(instance, raise_flag=False) + # Handle all other errors. + except: + # Print the exception. + print_exc() - # Handle all other errors. - except: - # Print the exception. - sys.stderr.write("Exception raised in thread.\n\n") - print_exc() - sys.stderr.write("\n\n\n") + # Release the lock. + finally: + status.exec_lock.release() +