Mercurial > hg > fail
comparison fail.py @ 4:8dc420754023
minor upgrades to prepare for streamlining
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Tue, 23 Aug 2016 16:29:13 -0700 |
| parents | d1880117acb5 |
| children | b407681e6f2c |
comparison
equal
deleted
inserted
replaced
| 3:d3a4f7b41944 | 4:8dc420754023 |
|---|---|
| 16 | 16 |
| 17 # parse command line | 17 # parse command line |
| 18 parser = argparse.ArgumentParser(description=__doc__) | 18 parser = argparse.ArgumentParser(description=__doc__) |
| 19 parser.add_argument('command', help="command to run") | 19 parser.add_argument('command', help="command to run") |
| 20 parser.add_argument('--code', dest='codes', default=(0,), nargs='+', | 20 parser.add_argument('--code', dest='codes', default=(0,), nargs='+', |
| 21 help="allowed exit codes") | 21 help="allowed exit codes [DEFAULT: 0]") |
| 22 parser.add_argument('-s', '--sleep', dest='sleep', | 22 parser.add_argument('-s', '--sleep', dest='sleep', |
| 23 type=float, default=1., | 23 type=float, default=1., |
| 24 help="sleep between iterations [DEFAULT: %(default)s]") | 24 help="sleep between iterations [DEFAULT: %(default)s]") |
| 25 options = parser.parse_args(args) | 25 options = parser.parse_args(args) |
| 26 | 26 |
| 27 try: | 27 try: |
| 28 | 28 |
| 29 # main loop | |
| 29 ctr = 0 | 30 ctr = 0 |
| 31 start_loop = time.time() | |
| 30 while True: | 32 while True: |
| 31 | 33 |
| 34 # note program start time | |
| 35 program_start_time = time.time() if ctr else start_loop | |
| 36 | |
| 37 # run the subcommand | |
| 38 process = subprocess.Popen(options.command, shell=True) | |
| 39 stdout, stderr = process.communicate() | |
| 32 ctr += 1 | 40 ctr += 1 |
| 33 | 41 |
| 34 # run it | 42 # print iteration information |
| 35 process = subprocess.Popen(options.command, shell=True) | |
| 36 _, _ = process.communicate() | |
| 37 | |
| 38 | |
| 39 print ("Iteration {}".format(ctr)) | 43 print ("Iteration {}".format(ctr)) |
| 40 | 44 |
| 41 # test it | 45 # test it |
| 42 if process.returncode not in options.codes: | 46 if process.returncode not in options.codes: |
| 43 sys.exit(process.returncode) | 47 sys.exit(process.returncode) |
