Adding an additional answer here due to a huge GOTCHA I had today.
Shared memory works across threads, but not processes. That is, if you have some module level thing like:
# mymodule
mycache = {}
mycache[key] = value
del mycache[key]
...
Deletes in one process will NOT be reflected in the cache of another process. However, deletes in one thread, if only one process is used, will persist across threads.
So if you are using shared memory like this, you have two options:
- all caches should be "safe" and "read through" (ie on cache miss, try to load the real data)
- always run threads=X but processes=1