diff python/multiproc.py @ 610:5ce25399da67

STUB: python/multiproc.py
author Jeff Hammel <k0scist@gmail.com>
date Sun, 02 Feb 2014 12:40:07 -0800
parents 3ea759399b8f
children 8e23bbc9c197
line wrap: on
line diff
--- a/python/multiproc.py	Sun Feb 02 12:00:03 2014 -0800
+++ b/python/multiproc.py	Sun Feb 02 12:40:07 2014 -0800
@@ -17,7 +17,7 @@
     """why would you name a subprocess object Popen?"""
 
     # http://docs.python.org/2/library/subprocess.html#popen-constructor
-    defaults = {'buffsize': 1, # line buffered
+    defaults = {'bufsize': 1, # line buffered
                 }
 
     def __init__(self, command, **kwargs):
@@ -35,7 +35,7 @@
         # output buffer
         self.output_buffer = tempfile.SpooledTemporaryFile()
         self.location = 0
-        self.output = []
+        self.output = ''
         _kwargs['stdout'] = self.output_buffer
 
         # launch subprocess
@@ -57,9 +57,7 @@
                 return process.kill()
 
             # read from output buffer
-            self.output_buffer.seek(self.location)
-            read = self.output_buffer.read()
-            self.location += len(read)
+            read = self.read()
 
             # naptime
             if sleep:
@@ -70,6 +68,14 @@
 
         return self.returncode # set by ``.poll()``
 
+    def read(self):
+        """read from the output buffer"""
+        self.output_buffer.seek(self.location)
+        read = self.output_buffer.read()
+        self.output += read
+        self.location += len(read)
+        return read
+
     def commandline(self):
         """returns string of command line"""
 
@@ -109,6 +115,7 @@
     if options.list_programs:
         for key in sorted(progs.keys()):
             print ('{}: {}'.format(key, subprocess.list2cmdline(progs[key])))
+        sys.exit(0)
 
     # select program
     prog = progs[options.program]