Catch and ignore KeyboardInterrupt exception
Per discussion in PR #40 comments. This will prevent a stack dump from littering the output when interrupting script run via Control-C. That was useful to have for a while, but probably is not anymore. Also, fix up a few corner cases where rc could be used without it having been set.
This commit is contained in:
parent
e65ec37962
commit
b11e6f4978
5 changed files with 10 additions and 6 deletions
|
@ -311,6 +311,7 @@ def main():
|
||||||
# ...unless influxdb-python package version is too old
|
# ...unless influxdb-python package version is too old
|
||||||
gstate.influx_client = InfluxDBClient(**opts.icargs)
|
gstate.influx_client = InfluxDBClient(**opts.icargs)
|
||||||
|
|
||||||
|
rc = 0
|
||||||
try:
|
try:
|
||||||
next_loop = time.monotonic()
|
next_loop = time.monotonic()
|
||||||
while True:
|
while True:
|
||||||
|
@ -321,7 +322,7 @@ def main():
|
||||||
time.sleep(next_loop - now)
|
time.sleep(next_loop - now)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Terminated:
|
except (KeyboardInterrupt, Terminated):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
loop_body(opts, gstate, shutdown=True)
|
loop_body(opts, gstate, shutdown=True)
|
||||||
|
|
|
@ -307,7 +307,7 @@ def main():
|
||||||
time.sleep(next_loop - now)
|
time.sleep(next_loop - now)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Terminated:
|
except (KeyboardInterrupt, Terminated):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
loop_body(opts, gstate, shutdown=True)
|
loop_body(opts, gstate, shutdown=True)
|
||||||
|
|
|
@ -184,6 +184,7 @@ def main():
|
||||||
|
|
||||||
signal.signal(signal.SIGTERM, handle_sigterm)
|
signal.signal(signal.SIGTERM, handle_sigterm)
|
||||||
|
|
||||||
|
rc = 0
|
||||||
try:
|
try:
|
||||||
next_loop = time.monotonic()
|
next_loop = time.monotonic()
|
||||||
while True:
|
while True:
|
||||||
|
@ -194,10 +195,11 @@ def main():
|
||||||
time.sleep(next_loop - now)
|
time.sleep(next_loop - now)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Terminated:
|
except (KeyboardInterrupt, Terminated):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
gstate.shutdown()
|
gstate.shutdown()
|
||||||
|
|
||||||
sys.exit(rc)
|
sys.exit(rc)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -303,7 +303,7 @@ def main():
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
logging.error("Database error: %s", e)
|
logging.error("Database error: %s", e)
|
||||||
rc = 1
|
rc = 1
|
||||||
except Terminated:
|
except (KeyboardInterrupt, Terminated):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
loop_body(opts, gstate, shutdown=True)
|
loop_body(opts, gstate, shutdown=True)
|
||||||
|
|
|
@ -274,6 +274,7 @@ def main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
signal.signal(signal.SIGTERM, handle_sigterm)
|
signal.signal(signal.SIGTERM, handle_sigterm)
|
||||||
|
|
||||||
|
rc = 0
|
||||||
try:
|
try:
|
||||||
next_loop = time.monotonic()
|
next_loop = time.monotonic()
|
||||||
while True:
|
while True:
|
||||||
|
@ -284,7 +285,7 @@ def main():
|
||||||
time.sleep(next_loop - now)
|
time.sleep(next_loop - now)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except Terminated:
|
except (KeyboardInterrupt, Terminated):
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
loop_body(opts, gstate, print_file, shutdown=True)
|
loop_body(opts, gstate, print_file, shutdown=True)
|
||||||
|
|
Loading…
Reference in a new issue