# HG changeset patch # User Jeff Hammel # Date 1391373607 28800 # Node ID 5ce25399da67efcb6663151ca91de12253363a19 # Parent 3ea759399b8ff14d67dbe94d802df9f2f8c00526 STUB: python/multiproc.py diff -r 3ea759399b8f -r 5ce25399da67 python/multiproc.py --- 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]