Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Add option to kill process after n minutes (#7)
Browse files Browse the repository at this point in the history
* Also add README for options -1 and -k
* Rearrange options in gtfsrdb.py
  • Loading branch information
chunhochow authored and barbeau committed Jul 20, 2017
1 parent b278959 commit 79ea526
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ the plumbing to get the data in place.

Other command line parameters:

* `-1` = Only issue a request once
* `-w` = Time to wait between requests (in seconds) (default=30s)
* `-k` = Kill process after this many minutes
* `-v` = Print generated SQL (verbose mode)
* `-l` = When multiple translations are available, prefer this language

Expand Down Expand Up @@ -238,4 +240,4 @@ The stop_delays view looks like this:

### Demo Project

See the [gtfsrdb-delay-demo](https://github.com/CUTR-at-USF/gtfsrdb-delay-demo) project for a sample web application that visualizes these delays.
See the [gtfsrdb-delay-demo](https://github.com/CUTR-at-USF/gtfsrdb-delay-demo) project for a sample web application that visualizes these delays.
14 changes: 11 additions & 3 deletions gtfsrdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@
p.add_option('-c', '--create-tables', default=False, dest='create',
action='store_true', help="Create tables if they aren't found")

p.add_option('-1', '--once', default=False, dest='once', action='store_true',
help='Only issue a request once')

p.add_option('-w', '--wait', default=30, type='int', metavar='SECS',
dest='timeout', help='Time to wait between requests (in seconds)')

p.add_option('-k', '--kill-after', default=0, dest='killAfter', type="float",
help='Kill process after this many minutes')

p.add_option('-v', '--verbose', default=False, dest='verbose',
action='store_true', help='Print generated SQL')

Expand All @@ -69,9 +75,6 @@
p.add_option('-l', '--language', default='en', dest='lang', metavar='LANG',
help='When multiple translations are available, prefer this language')

p.add_option('-1', '--once', default=False, dest='once', action='store_true',
help='only run the loader one time')

opts, args = p.parse_args()

if opts.quiet:
Expand Down Expand Up @@ -138,9 +141,14 @@ def getTrans(string, lang):
untranslated = t.text
return untranslated

if opts.killAfter > 0:
stop_time = datetime.datetime.now() + datetime.timedelta(minutes=opts.killAfter)

try:
keep_running = True
while keep_running:
if datetime.datetime.now() > stop_time:
sys.exit()
try:
# if True:
if opts.deleteOld:
Expand Down

0 comments on commit 79ea526

Please sign in to comment.