search

Home  >  Q&A  >  body text

python - flask 进程间通信

我使用gunicorn开了4个worker, 在发生请求的时候我需要对count变量进行加1, 我怎么保证这个count的正确性而不是被多个进程所抢占。

高洛峰高洛峰2887 days ago535

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:41:35

    It is recommended to use multiprocessing.managers
    Introduction: http://www.cnblogs.com/Xjng/p/4902514.html

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:41:35

    The easiest way is to add a global lock

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:41:35

    If your count is stored in the database, the database will handle concurrency for you.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 17:41:35

    Can be solved in the database. For example, redis has the INCR command.

    reply
    0
  • Cancelreply