mailr14399 - /branches/gui_testing/multi/processor.py


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

Header


Content

Posted by edward on August 19, 2011 - 12:25:
Author: bugman
Date: Fri Aug 19 12:25:22 2011
New Revision: 14399

URL: http://svn.gna.org/viewcvs/relax?rev=14399&view=rev
Log:
Some cleanups of the processor module.

This removed unused code and modifies docstrings and comments.


Modified:
    branches/gui_testing/multi/processor.py

Modified: branches/gui_testing/multi/processor.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/multi/processor.py?rev=14399&r1=14398&r2=14399&view=diff
==============================================================================
--- branches/gui_testing/multi/processor.py (original)
+++ branches/gui_testing/multi/processor.py Fri Aug 19 12:25:22 2011
@@ -122,14 +122,10 @@
 
     result = None
 
-    #try:
+    # Import the module.
     module = __import__(module_path, globals(), locals(), [])
     if verbose:
         print('loaded module %s' % module_path)
-    #except Exception, e:
-    #    if verbose:
-    #        print 'failed to load module_path %s' % module_path
-    #        print 'exception:', e
 
     #FIXME: needs more failure checking
     if module != None:
@@ -193,47 +189,8 @@
     return object
 
 
-# FIXME useful debugging code but where to put it
-def print_file_lineno(range=xrange(1, 2)):
-    for level in range:
-        print('<< ', level)
-        try:
-            file_name = sys._getframe(level).f_code.co_filename
-            function_name = sys._getframe(level).f_code.co_name
-            line_number = sys._getframe(level).f_lineno
-            msg = ': %s - %s - %d>>' % (file_name, function_name, 
line_number)
-            print(msg)
-        except Exception, e:
-            print(e)
-            break
-
-
-#FIXME: useful for debugging but where to put it
-def print_message(processor, message):
-    f = open('error' + repr(processor.rank()) + '.txt', 'a')
-    f.write(message + '\n')
-    f.flush()
-    f.close()
-
-
-#requires 2.4 decorators@abstract
-#def abstract(f):
-#    raise_unimplemented(f)
-
-#    return f
-
-
 def raise_unimplemented(method):
     '''Standard function for raising NotImplementedError for unimplemented 
abstract methods.
-
-    @todo:  For python versions >= 2.4 it is possible to use annotations and 
meta classes to provide
-            a very elegant implementation of abstract methods that check on 
class instantiation that
-            the derived class is a complete implementation of the abstract 
class. Note some people
-            think abstract classes shouldn't be used with python, however.  
They are proposed for
-            python 3k by Guido van Rossum in pep3119 ;-)
-
-    @see:   http://soiland.no/blog/py/abstract
-    @see:   http://www.python.org/dev/peps/pep-3119
 
     @param method:              The method which should be abstract.
     @type method:               class method
@@ -477,11 +434,7 @@
         self.orig_stdout = sys.__stdout__
         self.orig_stderr = sys.__stderr__
 
-        # CHECKME: integration with with stdo capture on slaves
-        # setup captured std output and error streams used for capturing and 
modifying proccessor
-        # output on masters and slaves
-        # processor id the replacement stdio file like objects are stored in 
the modulevariable
-        # global_stdio_capture
+        # Capture the STDIO.
         self.setup_stdio_capture(stdio_capture)
 
 
@@ -527,12 +480,9 @@
     def capture_stdio(self, stdio_capture=None):
         '''Enable capture of the STDOUT and STDERR by self.stdio_capture or 
user supplied streams.
 
-        @note:  On slave processors the replacement STDOUT and STDERR 
streams should be file like
-                objects which implement the methods truncate and getvalue 
(see PrependStringIO).
         @note:  Both or neither stream has to be replaced you can't just 
replace one!
 
-        @keyword stdio_capture: A pair of file like objects used to replace 
sys.stdout and
-                                sys.stderr respectively.
+        @keyword stdio_capture: A pair of file like objects used to replace 
sys.stdout and sys.stderr respectively.
         @type stdio_capture:    list of two file-like objects
         '''
 
@@ -825,34 +775,29 @@
     def std_stdio_capture(self, pre_strings=('', '')):
         '''Get the default sys.stdout and sys.stderr replacements.
 
-        On the master the replacement prepend output with 'MM S]' or MM E]' 
for the STDOUT and
-        STDERR channels respectively on slaves the outputs are replaced by 
StringIO objects that
-        prepend 'NN S]' or NN E]' for STDOUT and STDERR where NN is the rank 
of the processor. On
-        the slave processors the saved strings are retrieved for return to 
the master processor by
-        calling getvalue() on sys.stdout and sys.stderr.
-
-        @note:  By default STDOUT and STDERR are conjoined as otherwise the 
context of STDOUT and
-                STDERR messages are lost.
+        On the master the replacement prepend output with 'MM S]' or MM E]' 
for the STDOUT and STDERR channels respectively on slaves the outputs are 
replaced by StringIO objects that prepend 'NN S]' or NN E]' for STDOUT and 
STDERR where NN is the rank of the processor.
+
+        @note:  By default STDOUT and STDERR are conjoined as otherwise the 
context of STDOUT and STDERR messages are lost.
         @todo:  Improve segregation of sys.sdout and sys.stderr.
 
         @keyword pre_strings:   Pre strings for the sys.stdout and 
sys.stderr channels.
         @type pre_strings:      list of 2 str
-        @return:                File like objects to replace STDOUT and 
STDERR respectively in
-                                order.
+        @return:                File like objects to replace STDOUT and 
STDERR respectively in order.
         @rtype:                 tuple of two file-like objects
         '''
 
-        stdout_capture = None
-        stderr_capture = None
-
+        # The master processor.
         if self.rank() == 0:
             stdout_capture = PrependOut(pre_strings[0], sys.stdout)
             #FIXME: seems to be that writing to stderr results leads to 
incorrect serialisation of output
             stderr_capture = PrependOut(pre_strings[1], sys.stderr)
+
+        # The slaves.
         else:
             stdout_capture = PrependStringIO(pre_strings[0])
-            stderr_capture = PrependStringIO(pre_strings[1], 
target_stream=stdout_capture)
-
+            stderr_capture = PrependStringIO(pre_strings[1], 
stream=stdout_capture)
+
+        # Return the captured IO streams.
         return (stdout_capture, stderr_capture)
 
 
@@ -877,7 +822,6 @@
         return self.instance
 
 
-# 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.
 




Related Messages


Powered by MHonArc, Updated Fri Aug 19 12:40:02 2011