improved exception handling

master
agp8x 2015-09-29 19:39:41 +02:00
parent 4878b49af6
commit 3df904b8ab
2 changed files with 13 additions and 6 deletions

View File

@ -34,7 +34,7 @@ class ConnectionSetup(object):
connected_sensors = sensor_setup.setup_sensors()
return ipcon, connected_sensors
def disconnect_any(self, connections):
def disconnect_all(self, connections):
if connections is None:
connections = self.__connections__
for connection in connections:

17
main.py
View File

@ -72,16 +72,23 @@ if __name__ == "__main__":
# connection failed, log and exit
# TODO: logger.print_exception(inst)
log.error("connection failed: " + str(inst))
# noinspection PyUnboundLocalVariable
input("Press key to restart\n")
try:
input("Press key to restart\n")
except Exception as e:
log.critical("Exception: %s", e)
log.info("stop logging... @" + time.ctime() + "\n")
conSetup.disconnect_any(connections)
conSetup.disconnect_all()
connections = []
free_lock()
else:
log.critical("lock collision: lock 'all' active")
log.info("wait for retry (" + str(settings.waitDelay) + ")")
time.sleep(settings.waitDelay)
except KeyboardInterrupt:
log.info("keyboard-interrupt happened, cleaning up")
conSetup.disconnect_any(connections)
log.info("keyboard-interrupt happened")
except Exception as e:
log.critical("Exception: %s", e)
finally:
log.info("cleaning up")
conSetup.disconnect_all()
free_lock()