# HG changeset patch # User Jeff Hammel # Date 1391386457 28800 # Node ID bf3f8bc6d1b33a0033a8a440067f373f099f0c23 # Parent 839dfd35d5676a9936bb7d0eb796604ba0963c68 STUB: python/multiproc.py diff -r 839dfd35d567 -r bf3f8bc6d1b3 python/multiproc.py --- a/python/multiproc.py Sun Feb 02 15:33:18 2014 -0800 +++ b/python/multiproc.py Sun Feb 02 16:14:17 2014 -0800 @@ -58,6 +58,9 @@ # set end time self.end = time.time() + def poll(self): + return subprocess.Popen.poll(self) + def wait(self, maxtime=None, sleep=1., process_output=None): """ maxtime -- timeout in seconds @@ -67,7 +70,7 @@ # check for timeout curr_time = time.time() - run_time = curr_time - self.start + run_time = self.runtime() if maxtime is not None and run_time > maxtime: self.kill() self._finalize(process_output) @@ -81,7 +84,7 @@ time.sleep(sleep) # finalize - self._finalize() + self._finalize(process_output) return self.returncode # set by ``.poll()`` @@ -110,8 +113,8 @@ """returns time spent running or total runtime if completed""" if self.end is None: - return self.end - self.start - return time.time() - self.start + return time.time() - self.start + return self.end - self.start def main(args=sys.argv[1:]): @@ -151,19 +154,26 @@ # callback for output processing def process_output(output): - print output.upper() + print ('[{}] {}\n{}'.format(proc.runtime(), + output.upper(), + '-==-'*10)) - # # start the main subprocess loop - # # TODO -> OO - # output = tempfile.SpooledTemporaryFile() + + # LEGACY: output = tempfile.SpooledTemporaryFile() # start = time.time() # proc = subprocess.Popen(prog, stdout=output) # location = 0 - # while proc.poll() is None: - # curr_time = time.time() - # run_time = curr_time - start - # if run_time > options.time: - # proc.kill() + +# start the main subprocess loop +# while proc.poll() is None: + + # LEGACY: + # curr_time = time.time() + # run_time = curr_time - start + # if run_time > options.time: + # proc.kill() + + # output.seek(location) # read = output.read() # location += len(read)