Why does the Flask application create two processes?

As I understand it, Flask should create a thread and a second thread to run on it, but I see that two processes always work, not threads. Even for the simplest application.

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 processes:

 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's going on here?

+6
source share
1 answer

This is because you are starting the dev server with a reboot. The loader controls the file system for changes and launches the real application in another process, so there are two total processes.

You can disable the reboot by setting debug=False or use_reloader=False when calling run .

+13
source

Source: https://habr.com/ru/post/982681/


All Articles