Mercurial > hg > fail
annotate fail.py @ 2:d1880117acb5
attempt to correct documentation display on pypi
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Tue, 23 Aug 2016 14:58:00 -0700 |
parents | a4680e54c481 |
children | 8dc420754023 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
3 """ | |
4 run a program until it fails | |
5 """ | |
6 | |
7 # imports | |
8 import argparse | |
9 import subprocess | |
10 import sys | |
11 import time | |
12 | |
1 | 13 |
0 | 14 def main(args=sys.argv[1:]): |
15 """CLI""" | |
16 | |
17 # parse command line | |
18 parser = argparse.ArgumentParser(description=__doc__) | |
19 parser.add_argument('command', help="command to run") | |
20 parser.add_argument('--code', dest='codes', default=(0,), nargs='+', | |
21 help="allowed exit codes") | |
22 parser.add_argument('-s', '--sleep', dest='sleep', | |
23 type=float, default=1., | |
1 | 24 help="sleep between iterations [DEFAULT: %(default)s]") |
0 | 25 options = parser.parse_args(args) |
26 | |
27 try: | |
28 | |
29 ctr = 0 | |
30 while True: | |
31 | |
32 ctr += 1 | |
33 | |
34 # run it | |
35 process = subprocess.Popen(options.command, shell=True) | |
36 _, _ = process.communicate() | |
37 | |
2
d1880117acb5
attempt to correct documentation display on pypi
Jeff Hammel <k0scist@gmail.com>
parents:
1
diff
changeset
|
38 |
d1880117acb5
attempt to correct documentation display on pypi
Jeff Hammel <k0scist@gmail.com>
parents:
1
diff
changeset
|
39 print ("Iteration {}".format(ctr)) |
d1880117acb5
attempt to correct documentation display on pypi
Jeff Hammel <k0scist@gmail.com>
parents:
1
diff
changeset
|
40 |
0 | 41 # test it |
42 if process.returncode not in options.codes: | |
43 sys.exit(process.returncode) | |
44 | |
45 # loop control | |
46 time.sleep(options.sleep) | |
47 | |
48 | |
49 except KeyboardInterrupt: | |
50 sys.exit(0) | |
51 | |
52 if __name__ == '__main__': | |
53 main() |