Don't change object while iterating

Closes: #40
This commit is contained in:
Brian May
2015-12-09 10:22:28 +11:00
parent bea723c598
commit 4fdd715bc1
2 changed files with 19 additions and 6 deletions

View File

@ -328,14 +328,20 @@ def main(latency_control):
if dnshandlers:
now = time.time()
for channel, h in list(dnshandlers.items()):
remove = []
for channel, h in dnshandlers.items():
if h.timeout < now or not h.ok:
debug3('expiring dnsreqs channel=%d\n' % channel)
del dnshandlers[channel]
remove.append(channel)
h.ok = False
for channel in remove:
del dnshandlers[channel]
if udphandlers:
for channel, h in list(udphandlers.items()):
remove = []
for channel, h in udphandlers.items():
if not h.ok:
debug3('expiring UDP channel=%d\n' % channel)
del udphandlers[channel]
remove.append(channel)
h.ok = False
for channel in remove:
del udphandlers[channel]