Opened 10 years ago
Last modified 10 years ago
#23642 closed Bug
LocMemCache.incr is not thread safe — at Initial Version
Reported by: | Thomas C | Owned by: | nobody |
---|---|---|---|
Component: | Core (Cache system) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
LocMemCache
is documented as being thread-safe, but its incr
operation isn't: there is not lock wrapping the whole get+set operation.
The code below demonstrates the issue:
import threading from django.core.cache.backends.locmem import LocMemCache cache = LocMemCache('test', {}) cache.set('foo', 0) def increment(key): cache.incr(key) threads = [] for i in range(20): t = threading.Thread(target=increment, args=('foo',)) t.start() threads.append(t) for t in threads: t.join() print cache.get('foo') # Random results — 20 is expected
Note:
See TracTickets
for help on using tickets.