Skip to content

Commit 006ddf9

Browse files
committed
Deepcopy timeouts in do_expire method to avoid RuntimeError in Python 3.
1 parent 45c0099 commit 006ddf9

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
@@ -221,7 +222,9 @@ def do_expire(self):
221222
"""
222223
Expire objects assuming now == time
223224
"""
224-
for key, value in self.timeouts.items():
225+
# Deep copy to avoid RuntimeError: dictionary changed size during iteration
226+
_timeouts = deepcopy(self.timeouts)
227+
for key, value in _timeouts.items():
225228
if value - self.clock.now() < timedelta(0):
226229
del self.timeouts[key]
227230
# removing the expired key

0 commit comments

Comments
 (0)