mailr7749 - /branches/multi_processor_merge/multi/processor.py


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

Header


Content

Posted by edward on October 16, 2008 - 16:07:
Author: bugman
Date: Thu Oct 16 16:07:46 2008
New Revision: 7749

URL: http://svn.gna.org/viewcvs/relax?rev=7749&view=rev
Log:
Ordered all the classes alphabetically.


Modified:
    branches/multi_processor_merge/multi/processor.py

Modified: branches/multi_processor_merge/multi/processor.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/multi_processor_merge/multi/processor.py?rev=7749&r1=7748&r2=7749&view=diff
==============================================================================
--- branches/multi_processor_merge/multi/processor.py (original)
+++ branches/multi_processor_merge/multi/processor.py Thu Oct 16 16:07:46 2008
@@ -301,6 +301,103 @@
         # note we print to __stdout__ as sys.stdout may be a wrapper we 
applied
         traceback.print_exc(file=sys.__stdout__)
         processor.abort()
+
+
+class Capturing_exception(Exception):
+    '''A wrapper exception for an exception captured on a slave processor.
+
+    The wrapper will remember the stack trace on the remote machine and when 
raised and caught has a
+    string that includes the remote stack trace, which will be displayed 
along with the stack trace
+    on the master.
+    '''
+    def __init__(self,exc_info=None, rank='unknown', name='unknown'):
+        '''Initialise the wrapping exception.
+
+        @todo:   Would it be easier to pass a processor here.
+
+        @keyword exc_info:  Exception information as produced by 
sys.exc_info().
+        @type exc_info:     tuple
+        @keyword rank:      The rank of the processor on which the exception 
was raised.  The value
+                            is always greater than 1.
+        @type rank:         int
+        @keyword name:      The name of the processor on which the exception 
was raised as returned
+                            by processor.get_name().
+        @type name:         str
+        '''
+
+        Exception.__init__(self)
+        self.rank=rank
+        self.name=name
+        if exc_info == None:
+            
(exception_type,exception_instance,exception_traceback)=sys.exc_info()
+        else:
+            (exception_type,exception_instance,exception_traceback)=exc_info
+        #PY3K: this check can be removed once string based exceptions are no 
longer used
+       if type(exception_type) ==  str:
+                self.exception_name = exception_type + ' (legacy string 
exception)'
+                self.exception_string=exception_type
+        else:
+            self.exception_name =  exception_type.__name__
+            self.exception_string = exception_instance.__str__()
+
+        self.traceback = traceback.format_tb(exception_traceback)
+
+    def __str__(self):
+        '''Get the string describing this exception.
+
+        @return:    The string describing this exception.
+        @rtype:     str
+        '''
+        message ='''
+
+                     %s
+
+                     %s
+
+                     Nested Exception from sub processor
+                     Rank: %s  Name: %s
+                     Exception type: %s
+                     Message: %s
+
+                     %s
+
+
+                 '''
+        message = textwrap.dedent(message)
+        result =  message % ('-'*120, ''.join(self.traceback) ,self. rank, 
self.name, self.exception_name,
+                             self.exception_string, '-'*120)
+        return result
+
+
+class Memo(object):
+    '''A memo of objects and data.
+    
+    This is for a slave_command to provide to its results-commands upon 
return to the master
+    processor - designed for overriding by users.
+    '''
+
+    def memo_id(self):
+        '''Get the unique id for the memo.
+        
+        Currently this is the objects unique python id (note these ids can 
be recycled once the memo
+        has been garbage collected it cannot be used as a unique longterm 
hash).
+
+        @return:    A unique id for this memo.
+        @rtype:     int
+        '''
+        return id(self)
+
+
+
+class Null_result_command(Result_command):
+    '''An empty result command.
+
+    This command should be returned from slave_command if no other 
Result_command  is returned. This
+    allows the queue processor to register that the slave processor has 
completed its processing and
+    schedule new Slave-commands to it.
+    '''
+    def __init__(self,processor,completed=True):
+        
super(Null_result_command,self).__init__(processor=processor,completed=completed)
 
 
 class Processor(object):
@@ -714,6 +811,7 @@
 
         return (stdout_string,stderr_string)
 
+
 # TODO currently uni_processor doesn't have a process_result should this be 
integrated
 class Result(object):
     '''A basic result object returned from a slave processor via 
return_object.
@@ -766,6 +864,59 @@
         self.rank = processor.rank()
         '''The rank of the current processor, used in command scheduling on 
the master processor.'''
 
+
+class Result_command(Result):
+    '''A general result command - designed to be subclassed by users.
+
+    This is a general result command from a Slave command that will have its 
run() method called on
+    return to the master processor.
+
+    @see:   multi.processor.Slave_command.
+    '''
+
+    def __init__(self,processor,completed,memo_id=None):
+        #TODO: check this method is documnted by its parent
+        
super(Result_command,self).__init__(processor=processor,completed=completed)
+        self.memo_id=memo_id
+
+
+    def run(self,processor,memo):
+        '''The run method of the result command.
+
+        This method will be called when the result command is processed by 
the master and should
+        carry out any actions the slave command needs carried out on the 
master (e.g. save or
+        register results).
+
+        @see:   multi.processor.Processor.
+        @see:   multi.processor.Slave_command.
+        @see:   multi.processor.Memo.
+
+        @param processor:   The master processor that queued the original 
Slave_command.
+        @type processor:    Processor instance
+        @param memo:        A memo that was registered when the original 
slave command was placed on
+                            the queue. This provides local storage on the 
master.
+        @type memo:         Memo instance or None
+        '''
+        pass
+
+
+class Result_exception(Result_command):
+    '''Return and raise an exception from the salve processor.'''
+    def __init__(self,processor,exception,completed=True):
+        '''Initialise the result command with an exception.
+
+        @param exception:   An exception that was raised on the slave 
processor (note the real
+                            exception will be wrapped in a 
Capturing_exception.
+        @type exception:    Exception instance
+        '''
+        
super(Result_exception,self).__init__(processor=processor,completed=completed)
+        self.exception=exception
+
+    def run(self,processor,memo):
+        '''Raise the exception from the Slave_processor.'''
+        raise self.exception
+
+
 # TODO: make this a result_command
 class Result_string(Result):
     '''A simple result from a slave containing a result.
@@ -788,69 +939,6 @@
         '''
         
super(Result_string,self).__init__(processor=processor,completed=completed)
         self.string=string
-
-
-class Result_command(Result):
-    '''A general result command - designed to be subclassed by users.
-
-    This is a general result command from a Slave command that will have its 
run() method called on
-    return to the master processor.
-
-    @see:   multi.processor.Slave_command.
-    '''
-
-    def __init__(self,processor,completed,memo_id=None):
-        #TODO: check this method is documnted by its parent
-        
super(Result_command,self).__init__(processor=processor,completed=completed)
-        self.memo_id=memo_id
-
-
-    def run(self,processor,memo):
-        '''The run method of the result command.
-
-        This method will be called when the result command is processed by 
the master and should
-        carry out any actions the slave command needs carried out on the 
master (e.g. save or
-        register results).
-
-        @see:   multi.processor.Processor.
-        @see:   multi.processor.Slave_command.
-        @see:   multi.processor.Memo.
-
-        @param processor:   The master processor that queued the original 
Slave_command.
-        @type processor:    Processor instance
-        @param memo:        A memo that was registered when the original 
slave command was placed on
-                            the queue. This provides local storage on the 
master.
-        @type memo:         Memo instance or None
-        '''
-        pass
-
-class Null_result_command(Result_command):
-    '''An empty result command.
-
-    This command should be returned from slave_command if no other 
Result_command  is returned. This
-    allows the queue processor to register that the slave processor has 
completed its processing and
-    schedule new Slave-commands to it.
-    '''
-    def __init__(self,processor,completed=True):
-        
super(Null_result_command,self).__init__(processor=processor,completed=completed)
-
-
-
-class Result_exception(Result_command):
-    '''Return and raise an exception from the salve processor.'''
-    def __init__(self,processor,exception,completed=True):
-        '''Initialise the result command with an exception.
-
-        @param exception:   An exception that was raised on the slave 
processor (note the real
-                            exception will be wrapped in a 
Capturing_exception.
-        @type exception:    Exception instance
-        '''
-        
super(Result_exception,self).__init__(processor=processor,completed=completed)
-        self.exception=exception
-
-    def run(self,processor,memo):
-        '''Raise the exception from the Slave_processor.'''
-        raise self.exception
 
 
 class Slave_command(object):
@@ -903,92 +991,3 @@
         @type completed:    bool
         '''
         pass
-
-
-
-class Memo(object):
-    '''A memo of objects and data.
-    
-    This is for a slave_command to provide to its results-commands upon 
return to the master
-    processor - designed for overriding by users.
-    '''
-
-    def memo_id(self):
-        '''Get the unique id for the memo.
-        
-        Currently this is the objects unique python id (note these ids can 
be recycled once the memo
-        has been garbage collected it cannot be used as a unique longterm 
hash).
-
-        @return:    A unique id for this memo.
-        @rtype:     int
-        '''
-        return id(self)
-
-
-
-class Capturing_exception(Exception):
-    '''A wrapper exception for an exception captured on a slave processor.
-
-    The wrapper will remember the stack trace on the remote machine and when 
raised and caught has a
-    string that includes the remote stack trace, which will be displayed 
along with the stack trace
-    on the master.
-    '''
-    def __init__(self,exc_info=None, rank='unknown', name='unknown'):
-        '''Initialise the wrapping exception.
-
-        @todo:   Would it be easier to pass a processor here.
-
-        @keyword exc_info:  Exception information as produced by 
sys.exc_info().
-        @type exc_info:     tuple
-        @keyword rank:      The rank of the processor on which the exception 
was raised.  The value
-                            is always greater than 1.
-        @type rank:         int
-        @keyword name:      The name of the processor on which the exception 
was raised as returned
-                            by processor.get_name().
-        @type name:         str
-        '''
-
-        Exception.__init__(self)
-        self.rank=rank
-        self.name=name
-        if exc_info == None:
-            
(exception_type,exception_instance,exception_traceback)=sys.exc_info()
-        else:
-            (exception_type,exception_instance,exception_traceback)=exc_info
-        #PY3K: this check can be removed once string based exceptions are no 
longer used
-       if type(exception_type) ==  str:
-                self.exception_name = exception_type + ' (legacy string 
exception)'
-                self.exception_string=exception_type
-        else:
-            self.exception_name =  exception_type.__name__
-            self.exception_string = exception_instance.__str__()
-
-        self.traceback = traceback.format_tb(exception_traceback)
-
-    def __str__(self):
-        '''Get the string describing this exception.
-
-        @return:    The string describing this exception.
-        @rtype:     str
-        '''
-        message ='''
-
-                     %s
-
-                     %s
-
-                     Nested Exception from sub processor
-                     Rank: %s  Name: %s
-                     Exception type: %s
-                     Message: %s
-
-                     %s
-
-
-                 '''
-        message = textwrap.dedent(message)
-        result =  message % ('-'*120, ''.join(self.traceback) ,self. rank, 
self.name, self.exception_name,
-                             self.exception_string, '-'*120)
-        return result
-
-




Related Messages


Powered by MHonArc, Updated Thu Oct 16 16:40:04 2008