mailr15408 - in /1.3: multi/__init__.py relax.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on February 29, 2012 - 13:54:
Author: bugman
Date: Wed Feb 29 13:54:29 2012
New Revision: 15408

URL: http://svn.gna.org/viewcvs/relax?rev=15408&view=rev
Log:
Shifted the Application_callback class into the multi.__init__ module to 
shift it into the API.

The __init__ module now hopefully contains the entirety of the public 
interface or API of the
multi-processor package.  This should simplify the interaction of the package 
with the importing
program.


Modified:
    1.3/multi/__init__.py
    1.3/relax.py

Modified: 1.3/multi/__init__.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/multi/__init__.py?rev=15408&r1=15407&r2=15408&view=diff
==============================================================================
--- 1.3/multi/__init__.py (original)
+++ 1.3/multi/__init__.py Wed Feb 29 13:54:29 2012
@@ -120,6 +120,68 @@
 
 
 
+class Application_callback(object):
+    '''Call backs provided to the host application by the multi processor 
framework.
+
+    This class allows for independence from the host class/application.
+
+    @note:  B{The logic behind the design} the callbacks are defined as two 
attributes
+            self.init_master and self.handle_exception as handle_exception 
can be null (which is
+            used to request the use of the processors default error handling 
code). Note, however,
+            that a class with the equivalent methods would also works as 
python effectively handles
+            methods as attributes of a class. The signatures for the 
callback methods are documented
+            by the default methods default_init_master & 
default_handle_exception.
+    '''
+
+    def __init__(self, master):
+        '''Initialise the callback interface.
+
+        @param master:  The data for the host application. In the default 
implementation this is an
+                        object we call methods on but it could be anything...
+        @type master:   object
+        '''
+
+        self.master = master
+        '''The host application.'''
+
+        self.init_master = self.default_init_master
+        self.handle_exception = self.default_handle_exception
+
+
+    def default_handle_exception(self, processor, exception):
+        '''Handle an exception raised in the processor framework.
+
+        The function is responsible for aborting the processor by calling 
processor.abort() as its
+        final act.
+
+        @param processor:   The processor instance.
+        @type processor:    multi.processor.Processor instance
+        @param exception:   The exception raised by the processor or slave 
processor. In the case of
+                            a slave processor exception this may well be a 
wrapped exception of type
+                            multi.processor.Capturing_exception which was 
raised at the point the
+                            exception was received on the master processor 
but contains an enclosed
+                            exception from a slave.
+        @type exception:    Exception instance
+        '''
+
+        # Print the traceback.
+        traceback.print_exc(file=sys.stderr)
+
+        # Stop the processor.
+        processor.abort()
+
+
+    def default_init_master(self, processor):
+        '''Start the main loop of the host application.
+
+        @param processor:   The processor instance.
+        @type processor:    multi.processor.Processor instance
+        '''
+
+        self.master.run()
+
+
+
 class Processor_box(object):
     """A storage class for the Processor instance and its attributes.
 

Modified: 1.3/relax.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/relax.py?rev=15408&r1=15407&r2=15408&view=diff
==============================================================================
--- 1.3/relax.py (original)
+++ 1.3/relax.py Wed Feb 29 13:54:29 2012
@@ -54,8 +54,7 @@
 import generic_fns
 if dep_check.wx_module:
     import gui
-from multi import load_multiprocessor
-from multi.processor import Application_callback
+from multi import Application_callback, load_multiprocessor
 from prompt.gpl import gpl
 from prompt import interpreter
 import relax_errors




Related Messages


Powered by MHonArc, Updated Wed Feb 29 15:00:02 2012