improved exception handling
parent
4878b49af6
commit
3df904b8ab
2
Setup.py
2
Setup.py
|
|
@ -34,7 +34,7 @@ class ConnectionSetup(object):
|
||||||
connected_sensors = sensor_setup.setup_sensors()
|
connected_sensors = sensor_setup.setup_sensors()
|
||||||
return ipcon, connected_sensors
|
return ipcon, connected_sensors
|
||||||
|
|
||||||
def disconnect_any(self, connections):
|
def disconnect_all(self, connections):
|
||||||
if connections is None:
|
if connections is None:
|
||||||
connections = self.__connections__
|
connections = self.__connections__
|
||||||
for connection in connections:
|
for connection in connections:
|
||||||
|
|
|
||||||
15
main.py
15
main.py
|
|
@ -72,16 +72,23 @@ if __name__ == "__main__":
|
||||||
# connection failed, log and exit
|
# connection failed, log and exit
|
||||||
# TODO: logger.print_exception(inst)
|
# TODO: logger.print_exception(inst)
|
||||||
log.error("connection failed: " + str(inst))
|
log.error("connection failed: " + str(inst))
|
||||||
# noinspection PyUnboundLocalVariable
|
try:
|
||||||
input("Press key to restart\n")
|
input("Press key to restart\n")
|
||||||
|
except Exception as e:
|
||||||
|
log.critical("Exception: %s", e)
|
||||||
log.info("stop logging... @" + time.ctime() + "\n")
|
log.info("stop logging... @" + time.ctime() + "\n")
|
||||||
conSetup.disconnect_any(connections)
|
conSetup.disconnect_all()
|
||||||
|
connections = []
|
||||||
free_lock()
|
free_lock()
|
||||||
else:
|
else:
|
||||||
log.critical("lock collision: lock 'all' active")
|
log.critical("lock collision: lock 'all' active")
|
||||||
log.info("wait for retry (" + str(settings.waitDelay) + ")")
|
log.info("wait for retry (" + str(settings.waitDelay) + ")")
|
||||||
time.sleep(settings.waitDelay)
|
time.sleep(settings.waitDelay)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
log.info("keyboard-interrupt happened, cleaning up")
|
log.info("keyboard-interrupt happened")
|
||||||
conSetup.disconnect_any(connections)
|
except Exception as e:
|
||||||
|
log.critical("Exception: %s", e)
|
||||||
|
finally:
|
||||||
|
log.info("cleaning up")
|
||||||
|
conSetup.disconnect_all()
|
||||||
free_lock()
|
free_lock()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue