diff --git a/core/cleanup.py b/core/cleanup.py index 644e648..dcf7f79 100644 --- a/core/cleanup.py +++ b/core/cleanup.py @@ -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)