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
Browse files Browse the repository at this point in the history
  • Loading branch information
chunhochow committed Jul 18, 2017
1 parent b278959 commit 4df85ef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gtfsrdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
p.add_option('-1', '--once', default=False, dest='once', action='store_true',
help='only run the loader one time')

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

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 4df85ef

Please sign in to comment.