Mercurial > hg > config
changeset 608:9a5cdd49af53
STUB: python/multiproc.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 02 Feb 2014 11:37:34 -0800 |
parents | 567492ef7b57 |
children | 3ea759399b8f |
files | python/multiproc.py |
diffstat | 1 files changed, 29 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/python/multiproc.py Sun Feb 02 11:16:51 2014 -0800 +++ b/python/multiproc.py Sun Feb 02 11:37:34 2014 -0800 @@ -65,6 +65,10 @@ if sleep: time.sleep(sleep) + # reset tempfile + output.seek(0) + + return self.returncode # set by ``.poll()`` def commandline(self): """returns string of command line""" @@ -101,30 +105,36 @@ help="list available programs") options = parser.parse_args(args) + # list programs + if options.list_programs: + for key in sorted(progs.keys()): + print ('{}: {}'.format(key, subprocess.list2cmdline(progs[key]))) # select program prog = progs[options.program] - # start the main subprocess loop - # TODO -> OO - 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() - output.seek(location) - read = output.read() - location += len(read) - print ('[{}] {}\n{}'.format(run_time, read, '-==-'*10)) - if options.sleep: - time.sleep(options.sleep) + proc = Process(prog) - # reset tempfile - output.seek(0) + # # start the main subprocess loop + # # TODO -> OO + # 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() + # output.seek(location) + # read = output.read() + # location += len(read) + # print ('[{}] {}\n{}'.format(run_time, read, '-==-'*10)) + # if options.sleep: + # time.sleep(options.sleep) + + # # reset tempfile + # output.seek(0) n_lines = len(output.read().splitlines()) print ("{}: {} lines".format(subprocess.list2cmdline(prog), n_lines))