Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a Flask app create two process? [duplicate]

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?

like image 221
arash javanmard Avatar asked Feb 18 '15 13:02

arash javanmard


People also ask

Why flask is the best choice for web app development?

The primary reason behind the simplicity of Flask is its documentation that becomes handy for developers in case of confusion. Flask is one of the most recognized web app frameworks that allow developers to have complete control over the codebase, which is small.

Can flask serve up HTML webpages?

A Flask web application can serve up HTML webpages just as easy as "Hello world", because HTML is just text. Next » Making a simple Flask app for viewing YouTube videos

Can a flask app respond to an arbitrary URL path?

Table of contents Getting started At the end of this lesson, you'll be able to create an app that can respond to any arbitrary URL path: But first, let's revisit the app.pyfor the most basic Flask app. Try to rewrite it from scratch, just from memory:

What is flask-apscheduler in Python 3 flask?

When you are building your HTTP server with Python 3 Flask, Flask-APScheduler gives you the facilities to schedule tasks to be executed in the background. In this post, we look at how we can get Flask-APScheduler in your Python 3 Flask application to run multiple tasks in parallel, from a single HTTP request.


Video Answer


1 Answers

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.

like image 99
davidism Avatar answered Sep 19 '22 18:09

davidism