mailr7781 - /branches/multi_processor_merge/multi/uni_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 - 18:25:
Author: bugman
Date: Thu Oct 16 18:25:38 2008
New Revision: 7781

URL: http://svn.gna.org/viewcvs/relax?rev=7781&view=rev
Log:
Clean up of the Uni_processor class.

Old, commented out code has been deleted, a few docstrings added, 
whitespacing completely fixed, and
class methods alphabetically sorted.


Modified:
    branches/multi_processor_merge/multi/uni_processor.py

Modified: branches/multi_processor_merge/multi/uni_processor.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/multi_processor_merge/multi/uni_processor.py?rev=7781&r1=7780&r2=7781&view=diff
==============================================================================
--- branches/multi_processor_merge/multi/uni_processor.py (original)
+++ branches/multi_processor_merge/multi/uni_processor.py Thu Oct 16 18:25:38 
2008
@@ -26,94 +26,70 @@
 
 # Python module imports.
 import threading, Queue
-import sys,os
+import sys, os
 
 # relax module imports.
 import multi
 from multi.processor import Processor, Result_command, Result_string
 
 
-#FIXME need to subclass
 class Uni_processor(Processor):
+    """The uni-processor class."""
 
+    def __init__(self, processor_size, callback):
+        """Initialise the class.
 
-    def __init__(self,processor_size,callback):
-        
super(Uni_processor,self).__init__(processor_size=1,callback=callback)
+        @param processor_size:  The number of processors.
+        @type processor_size:   int
+        @param callback:        The callback object.
+        @type callback:         ?
+        """
+        super(Uni_processor, self).__init__(processor_size=1, 
callback=callback)
 
         if processor_size > 1:
             print 'warning: uniprocessor can only support 1 processor you 
requested %d' % processor_size
             print 'continuing...\n'
 
+        self.command_queue = []
+        self.memo_map = {}
 
-        self.command_queue=[]
-        self.memo_map={}
+        self.slave_stdio_capture = self.std_stdio_capture(pre_strings=('', 
''))
 
-        self.slave_stdio_capture = 
self.std_stdio_capture(pre_strings=('',''))
 
-    def add_to_queue(self,command,memo=None):
+    def add_to_queue(self, command, memo=None):
         self.command_queue.append(command)
         if memo != None:
             command.set_memo_id(memo)
-            self.memo_map[memo.memo_id()]=memo
+            self.memo_map[memo.memo_id()] = memo
 
-    def run_queue(self):
-        #FIXME: need a finally here to cleanup exceptions states for windows 
etc
-
-        last_command = len(self.command_queue)-1
-        for i,command  in enumerate(self.command_queue):
-            completed = (i == last_command)
-
-            self.capture_stdio(self.slave_stdio_capture)
-            command.run(self,completed)
-            self.restore_stdio()
-
-        #self.run_command_queue()
-        #TODO: add cheques for empty queuese and maps if now warn
-        del self.command_queue[:]
-        self.memo_map.clear()
-# FIXME: remove me
-#    def run_command_queue(self):
-#            for command in self.command_queue:
-#                command.run(self)
-
-    def run(self):
-#        start_time =  time.clock()
-        try:
-            self.pre_run()
-            self.callback.init_master(self)
-            self.post_run()
-        except Exception,e:
-            self.callback.handle_exception(self,e)
-
-#        end_time = time.clock()
-#        time_diff= end_time - start_time
-#        time_delta = datetime.timedelta(seconds=time_diff)
-#        print 'overall runtime: ' + time_delta.__str__() + '\n'
-
-
-    def get_name(self):
-        # FIXME may need system dependent changes
-        return '%s-%s' % (os.getenv('HOSTNAME'),os.getpid())
 
     def exit(self):
         sys.exit()
 
-#    def on_master(self):
-#        return True
-
-
-    def rank(self):
-        return 0
-
-    def processor_size(self):
-        return 1
 
     def get_intro_string(self):
         return '''uniprocessor'''
 
 
 
-    def return_object(self,result):
+    def get_name(self):
+        # FIXME may need system dependent changes
+        return '%s-%s' % (os.getenv('HOSTNAME'), os.getpid())
+
+
+#    def on_master(self):
+#        return True
+
+
+    def processor_size(self):
+        return 1
+
+
+    def rank(self):
+        return 0
+
+
+    def return_object(self, result):
 
         local_save_stdout = sys.stdout
         local_save_stderr = sys.stderr
@@ -124,20 +100,43 @@
                    #       and finalise mpi (or restart it if we can!
             raise result
         elif isinstance(result, Result_command):
-            memo=None
+            memo = None
             if result.memo_id != None:
-                memo=self.memo_map[result.memo_id]
-            result.run(self,memo)
+                memo = self.memo_map[result.memo_id]
+            result.run(self, memo)
             if result.memo_id != None and result.completed:
                 del self.memo_map[result.memo_id]
 
         elif isinstance(result, Result_string):
             sys.stdout.write(result.string)
         else:
-            message = 'Unexpected result type \n%s \nvalue%s' 
%(result.__class__.__name__,result)
+            message = 'Unexpected result type \n%s \nvalue%s' 
%(result.__class__.__name__, result)
             raise Exception(message)
         sys.stdout = local_save_stdout
         sys.stderr = local_save_stderr
 
 
+    def run(self):
+        try:
+            self.pre_run()
+            self.callback.init_master(self)
+            self.post_run()
+        except Exception, e:
+            self.callback.handle_exception(self, e)
 
+
+    def run_queue(self):
+        #FIXME: need a finally here to cleanup exceptions states for windows 
etc
+
+        last_command = len(self.command_queue)-1
+        for i, command  in enumerate(self.command_queue):
+            completed = (i == last_command)
+
+            self.capture_stdio(self.slave_stdio_capture)
+            command.run(self, completed)
+            self.restore_stdio()
+
+        #self.run_command_queue()
+        #TODO: add cheques for empty queues and maps if now warn
+        del self.command_queue[:]
+        self.memo_map.clear()




Related Messages


Powered by MHonArc, Updated Thu Oct 16 18:40:03 2008