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:
sparky8512 2022-03-02 14:48:51 -08:00
parent e65ec37962
commit b11e6f4978
5 changed files with 10 additions and 6 deletions

View file

@ -311,6 +311,7 @@ def main():
# ...unless influxdb-python package version is too old
gstate.influx_client = InfluxDBClient(**opts.icargs)
rc = 0
try:
next_loop = time.monotonic()
while True:
@ -321,7 +322,7 @@ def main():
time.sleep(next_loop - now)
else:
break
except Terminated:
except (KeyboardInterrupt, Terminated):
pass
finally:
loop_body(opts, gstate, shutdown=True)

View file

@ -307,7 +307,7 @@ def main():
time.sleep(next_loop - now)
else:
break
except Terminated:
except (KeyboardInterrupt, Terminated):
pass
finally:
loop_body(opts, gstate, shutdown=True)

View file

@ -184,6 +184,7 @@ def main():
signal.signal(signal.SIGTERM, handle_sigterm)
rc = 0
try:
next_loop = time.monotonic()
while True:
@ -194,10 +195,11 @@ def main():
time.sleep(next_loop - now)
else:
break
except Terminated:
except (KeyboardInterrupt, Terminated):
pass
finally:
gstate.shutdown()
sys.exit(rc)

View file

@ -303,7 +303,7 @@ def main():
except sqlite3.Error as e:
logging.error("Database error: %s", e)
rc = 1
except Terminated:
except (KeyboardInterrupt, Terminated):
pass
finally:
loop_body(opts, gstate, shutdown=True)

View file

@ -274,6 +274,7 @@ def main():
sys.exit(1)
signal.signal(signal.SIGTERM, handle_sigterm)
rc = 0
try:
next_loop = time.monotonic()
while True:
@ -284,7 +285,7 @@ def main():
time.sleep(next_loop - now)
else:
break
except Terminated:
except (KeyboardInterrupt, Terminated):
pass
finally:
loop_body(opts, gstate, print_file, shutdown=True)