Skip to content

Commit 8fba948

Browse files
committed
Merge pull request #98 from vovanbo/runtime-error-bug-fix
Deepcopy timeouts in do_expire method to avoid RuntimeError in Python 3
2 parents a02fcd0 + 006ddf9 commit 8fba948

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mockredis/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import division
22
from collections import defaultdict
3+
from copy import deepcopy
34
from itertools import chain
45
from datetime import datetime, timedelta
56
from hashlib import sha1
@@ -229,7 +230,9 @@ def do_expire(self):
229230
"""
230231
Expire objects assuming now == time
231232
"""
232-
for key, value in self.timeouts.items():
233+
# Deep copy to avoid RuntimeError: dictionary changed size during iteration
234+
_timeouts = deepcopy(self.timeouts)
235+
for key, value in _timeouts.items():
233236
if value - self.clock.now() < timedelta(0):
234237
del self.timeouts[key]
235238
# removing the expired key

0 commit comments

Comments
 (0)