[tor-commits] [doctor/master] Can't modify during iteration

atagar at torproject.org atagar at torproject.org
Sun Oct 4 20:47:09 UTC 2015


commit db8fc25e902c913f3ed683960681cef8dd7444a5
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Oct 4 13:41:40 2015 -0700

    Can't modify during iteration
    
    Oops, we'd hit 'RuntimeError: dictionary changed size during iteration' during
    the bit where we clear out old entries.
---
 fingerprint_change_checker.py |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fingerprint_change_checker.py b/fingerprint_change_checker.py
index 289f3c0..72cca9b 100755
--- a/fingerprint_change_checker.py
+++ b/fingerprint_change_checker.py
@@ -43,10 +43,11 @@ def main():
 
       # drop fingerprint changes that are over thirty days old
 
-      for fp in prior_fingerprints:
-        if time.time() - prior_fingerprints[fp] > THIRTY_DAYS:
-          log.debug("Removing fingerprint for %s:%s (%s) which was published %i days ago" % (relay.address, relay.or_port, fp, prior_fingerprints[fp] / 60 / 60 / 24))
-          del prior_fingerprints[fp]
+      old_fingerprints = [fp for fp in prior_fingerprints if (time.time() - prior_fingerprints[fp] > THIRTY_DAYS)]
+
+      for fp in old_fingerprints:
+        log.debug("Removing fingerprint for %s:%s (%s) which was published %i days ago" % (relay.address, relay.or_port, fp, prior_fingerprints[fp] / 60 / 60 / 24))
+        del prior_fingerprints[fp]
 
       # if we've changed more than three times in the last thirty days then alarm
 



More information about the tor-commits mailing list