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?
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.
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
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:
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With