Defensive coding

This commit is contained in:
Ian Renton
2025-11-29 16:15:49 +00:00
parent 8a4f23ac72
commit ca31d23b4a

View File

@@ -35,13 +35,21 @@ class CleanupTimer:
# Explicitly clean up any spots and alerts that have expired
for id in list(self.spots.iterkeys()):
spot = self.spots[id]
if spot.expired():
self.spots.delete(id)
try:
spot = self.spots[id]
if spot.expired():
self.spots.delete(id)
except KeyError:
# Must have already been deleted, OK with that
pass
for id in list(self.alerts.iterkeys()):
alert = self.alerts[id]
if alert.expired():
self.alerts.delete(id)
try:
alert = self.alerts[id]
if alert.expired():
self.alerts.delete(id)
except KeyError:
# Must have already been deleted, OK with that
pass
self.status = "OK"
self.last_cleanup_time = datetime.now(pytz.UTC)