我使用gunicorn开了4个worker, 在发生请求的时候我需要对count变量进行加1, 我怎么保证这个count的正确性而不是被多个进程所抢占。
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
It is recommended to use multiprocessing.managers Introduction: http://www.cnblogs.com/Xjng/p/4902514.html
The easiest way is to add a global lock
If your count is stored in the database, the database will handle concurrency for you.
Can be solved in the database. For example, redis has the INCR command.
It is recommended to use multiprocessing.managers
Introduction: http://www.cnblogs.com/Xjng/p/4902514.html
The easiest way is to add a global lock
If your count is stored in the database, the database will handle concurrency for you.
Can be solved in the database. For example, redis has the INCR command.