问题
I have a server code with a global dictionary variable. It works nice with a single process gunicorn but it got errors when I make it multiprocesses since one values are not reach in this dictionary. I believe it is because this dictionary cannot be shared between processes. Do you know any workaround for this kind of a problem?
回答1:
I'm sorry to say that if you're trying to access to a shared python object between different instances from Gunicorn workers (gevent for example) you'll need to implement it using a shared service such loading/saving into Redis Database.
Since each Gunicorn worker process has it's own process id, you cannot access shared memory from other process.
Here you'll find more info: https://github.com/benoitc/gunicorn/issues/1026
Regards.
回答2:
I do the following, maybe not an exact solution but still works. I use Redis on pyredis to keep the values need to be shared btw processes. And it is pretty easy after you installed Redis.
来源:https://stackoverflow.com/questions/41939863/how-to-share-dictionary-between-gunicorn-processes