How to share dictionary between gunicorn processes?

萝らか妹 提交于 2019-12-24 01:58:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!