mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-12-13 07:33:39 +00:00
Defensive coding
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user