liveBook · Manning

Event loop

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

An event loop is a control structure that waits for events and repeatedly dispatches them for processing.

An event loop keeps a web server available without an explicit application loop. It waits for network events, such as HTTP requests, then dispatches them for processing while remaining mostly idle between events. section 6.4.2

A Flask server waiting for requests

Running a Flask app starts an event loop that monitors port 5000. A request for / calls home() and returns “Hello World”; a request for /something receives a 404 response while the server continues running. section 6.4.2

from flask import Flask      #1
 
app = Flask(__name__)        #2
 
@app.route("/")              #3
def home():                  #4
    return "Hello World!"

Inspect the minimal Flask application whose route is dispatched by the server event loop. section 6.4.2

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Defines event waiting and dispatch behavior, but stops short of showing the loop’s internal implementation.
Examples
Uses a Flask home route on port 5000 and an undefined /something route that produces a 404 response.
What you can do after
Operate a Flask server and understand how it remains active while waiting for requests.
How it connects
Connects network sockets, HTTP requests, URL routing, Flask, and error handling.

Also explained in

Compare how 11 books explain event loop →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.