当我将gunicorn放在具有以下方法的Flask服务前面时:
@app.route('/testr/', methods=['POST'])
def test():
atomic_section_here
根据我的理解,我可以创建多个工人(比方说5)。这是否意味着我使用自己的解释器获得5个进程?或者我是否使用multiprocessing
得到了一个解释器生成的5个进程?
如果我希望关键部分是原子的,我可以在该文件的顶层初始化一个锁并在关键部分内获取它吗?
答案 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.