为什么Flask应用程序创建两个进程? [英] Why does a Flask app create two process?

查看:541
本文介绍了为什么Flask应用程序创建两个进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,Flask应该创建一个线程和第二个线程来运行它,但是我所看到的总是有两个进程,而不是线程,正在运行。
即使是最简单的应用程序。

  from flask导入Flask $ b $ from flask导入render_template,request,flash ,会话,重定向

app = Flask(__ name__)

@ app.route('/')
def hello_world():
return' Hello World!'

app.run(host =192.168.21.73,port = 5000,debug = True)

你可以看到两个进程正在运行:

  ps -x 
5026 ttyO0 S + 0:01 / usr / bin / python ./test_flask.py
5031 ttyO0 Sl + 0:45 / usr / bin / python ./test_flask.py

这里发生了什么事情?

解决方案

用reloader重新运行dev服务器。重新加载程序监视文件系统的变化,并在不同的进程启动真正的应用程序,所以有两个总进程。



您可以通过设置<$ c $当调用 run 时,c> debug = False 或 use_reloader = False


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

What is happening here?

解决方案

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.

You can disable the reloader by settting debug=False or use_reloader=False when calling run.

这篇关于为什么Flask应用程序创建两个进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆