在烧瓶顶部的Gunicorn(关键部分)

时间:2015-04-15 01:00:05

标签: python gunicorn

当我将gunicorn放在具​​有以下方法的Flask服务前面时:

@app.route('/testr/', methods=['POST'])
def test():
  atomic_section_here

根据我的理解,我可以创建多个工人(比方说5)。这是否意味着我使用自己的解释器获得5个进程?或者我是否使用multiprocessing得到了一个解释器生成的5个进程?

如果我希望关键部分是原子的,我可以在该文件的顶层初始化一个锁并在关键部分内获取它吗?

1 个答案:

答案 0 :(得分:1)

您从1个解释器通过multiprocessing生成了5个进程。您可以在路线中mutltiprocessing.Lock().aquire和gunicorn.conf中preload_app = True的工人之间共享锁定。

Here is some reading about the design of Gunicorn, including the workers.

Here is a relevant question and answer about sharing the lock.