为什么 Flask 应用程序会创建两个进程? [英] Why does a Flask app create two process?
问题描述
据我所知,Flask 应该创建一个线程和第二个线程来运行它,但我看到的是总是有两个进程在运行,而不是线程.即使是最简单的应用.
As far as I understood Flask should create a thread and a second thread to run on it, but what I see is there are always two processes, not threads, running. Even for the simplest app.
from flask import Flask
from flask import render_template, request, flash, session, redirect
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
app.run(host="192.168.21.73", port=5000, debug=True)
可以看到有两个进程在运行:
You can see two process running:
ps -x
5026 ttyO0 S+ 0:01 /usr/bin/python ./test_flask.py
5031 ttyO0 Sl+ 0:45 /usr/bin/python ./test_flask.py
这里发生了什么?
推荐答案
这是因为您正在使用重新加载器运行开发服务器.重新加载器监控文件系统的变化,并在不同的进程中启动真正的应用程序,所以总共有两个进程.
It's because you're running the dev server with the reloader. The reloader monitors the filesystem for changes and starts the real app in a different process, so there are two total processes.
您可以通过在调用 run
时设置 debug=False
或 use_reloader=False
来禁用重载器.
You can disable the reloader by settting debug=False
or use_reloader=False
when calling run
.
这篇关于为什么 Flask 应用程序会创建两个进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!