Why does a Flask app create two process? [duplicat

2019-01-27 22:45发布

This question already has an answer here:

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?

1条回答
做自己的国王
2楼-- · 2019-01-27 23:45

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.

查看更多
登录 后发表回答