Event loop
An event loop is a runtime mechanism that repeatedly selects ready events or tasks and dispatches their associated work for execution.
Python Concurrency with asyncio
An event loop is a control mechanism that repeatedly selects runnable work, executes it, and responds when suspended work becomes ready.
- How it is used
- Coordinates asyncio tasks so I/O-bound operations progress concurrently without stopping a single Python thread.
- How deep it goes
- Explains queues, suspension, socket selectors, timeouts, manual management, and a simplified custom implementation, while deferring production completeness.
- Examples
- Uses web requests, non-blocking socket selectors, asyncio echo servers, Tkinter loops, and a custom socket server.
- What you can do after
- Build and operate asyncio applications, schedule coroutines, manage loops, and diagnose blocking CPU-bound or I/O code.
Read how Python Concurrency with asyncio explains event loop →
Secrets of the JavaScript Ninja, Second Edition
A runtime scheduling mechanism that coordinates when queued events and callbacks are handled by an application.
- How it is used
- Coordinates event handlers and other browser work during interactive page execution.
- How deep it goes
- Builds from a single event queue to macrotask and microtask queues, then works through delayed timer execution.
- Examples
- Traces mousemove and click DOM updates and a queued click, timeout, and interval timing scenario.
- What you can do after
- Diagnose/debug why an event or timer handler waits despite its event occurring or its delay expiring.
Read how Secrets of the JavaScript Ninja, Second Edition explains event loop →
Latency
An event loop is a control-flow pattern that waits for events, detects activity from event sources, and dispatches events to handlers.
- How it is used
- Coordinates asynchronous I/O across many connections without assigning separate resources to each connection.
- How deep it goes
- Works through a basic Rust polling loop and event dispatch, leaving OS-specific multiplexing behind a poll() method.
- Examples
- Uses socket readiness, timer expiry, request handling, and a Rust polling loop to illustrate dispatch.
- What you can do after
- Evaluate/understand when an event loop can keep an I/O-bound server responsive and why blocking handlers undermine it.
Grokking Concurrency
An event loop is a control-flow pattern that repeatedly waits for pending events, selects their handlers, and invokes those handlers.
- How it is used
- Coordinates event handlers and cooperative tasks so a single-threaded server can respond to multiple clients.
- How deep it goes
- Works from a queued-event loop through select-based socket callbacks to ready-task scheduling, including blocking and cooperative-yield limits.
- Examples
- Uses queued knock-and-reply events, a select-based pizza server, and a coroutine-driven pizza server.
- What you can do after
- Build it from scratch as a Python event queue or socket-ready dispatcher, and diagnose handlers that block the loop.
The Joy of JavaScript
An event loop is a runtime scheduling mechanism that repeatedly dequeues and executes pending callbacks or tasks to drive asynchronous execution.
- How it is used
- Places the event loop behind callbacks, promises, and async/await as the scheduling model for asynchronous JavaScript.
- How deep it goes
- Explains the callback queue and interleaved scheduling at a high level, without detailing queue rules or engine internals.
- Examples
- Contrasts synchronous, callback-based, and promise-based Node.js file reads and considers a module using top-level await.
- What you can do after
- Evaluate/understand how asynchronous work can proceed alongside main code and why dependent modules wait at top-level await.
Build a Frontend Web Framework (From Scratch)
The JavaScript runtime mechanism that coordinates execution of synchronous code and queued asynchronous tasks.
- How it is used
- Coordinates asynchronous lifecycle hooks, scheduler jobs, user interactions, timers, and DOM rendering.
- How deep it goes
- Explains the execution stack, two queues, four cycle steps, and microtask priority without pursuing full specification detail.
- Examples
- Uses event listeners, timers, promise callbacks, lifecycle hooks, nextTick(), and scheduler jobs.
- What you can do after
- Evaluate asynchronous ordering and schedule lifecycle or update work using microtasks.
Read how Build a Frontend Web Framework (From Scratch) explains event loop →
Building LLM Applications with DSPy
An event loop schedules and runs asynchronous tasks, switching between them when they complete or suspend.
- How it is used
- Coordinates coroutine tasks, switching between them when a task completes or pauses at an await point.
- How deep it goes
- Explains task switching at await points and that only one task executes at a time.
- Examples
- Demonstrates two sleeping coroutines run with asyncio.gather(), with their results and elapsed time printed.
- What you can do after
- Apply via asyncio.run() to start an event loop and run coroutine tasks.
Read how Building LLM Applications with DSPy explains event loop →
Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi
An event loop is a control structure that repeatedly waits for input or events and dispatches corresponding handlers.
- How it is used
- Runs interactive Pygame controls and live camera applications that repeatedly receive input, process data, display results, and detect exit requests.
- How deep it goes
- Implements initialization, polling, dispatch, frame-rate control, exit handling, camera cleanup, and face processing without exploring lower-level scheduling internals.
- Examples
- Uses a Pygame event printer and a live camera preview that marks detected faces until window, Q, or Esc input ends execution.
- What you can do after
- Apply it via Pygame or cv2 to build responsive input handlers, camera previews, controlled exits, and reusable robot interaction loops.
Read how Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi explains event loop →
Spring in Action, Sixth Edition
An event loop is a concurrency mechanism that repeatedly receives events and dispatches their handlers, typically without dedicating a thread to each request.
- How it is used
- Uses event-driven request handling to improve scalability in reactive web applications and APIs.
- How deep it goes
- Explains request, callback, and completion-event flow, then contrasts event-loop handling with servlet-based multithreading.
- Examples
- Illustrates callbacks for intensive database and network operations and visualizes handling more requests with fewer threads.
- What you can do after
- Apply it via Spring WebFlux when building reactive APIs that use nonblocking asynchronous request handling.
Read how Spring in Action, Sixth Edition explains event loop →
Grokking Simplicity
A runtime mechanism that repeatedly retrieves queued events or callbacks and invokes them when the call stack is available.
- How it is used
- Coordinates browser events and asynchronous callbacks while isolating separate execution timelines.
- How deep it goes
- Defines jobs, callbacks, queue processing, and single-threaded execution, then traces a complete AJAX interaction.
- Examples
- Uses click handling, AJAX cart updates, nested dog-and-cat requests, and a dishwashing callback refactoring exercise.
- What you can do after
- Apply it via JavaScript callbacks to structure asynchronous results instead of relying on immediate return values.
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.
- How it is used
- Keeps a Flask web server responsive by waiting for incoming HTTP requests and dispatching them to defined routes.
- 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.
Read how The Well-Grounded Python Developer: How the pros use Python and Flask explains event loop →
Related concepts
- microtask queueuses · A microtask queue is an event-loop queue that holds pending microtasks for processing after the current synchronous execution and before subsequent task processing.
- queueuses · A queue is an ordered collection that holds items for retrieval or processing, typically removing them in the order they were added.
- macrotask queueuses · A macrotask queue is a runtime-managed queue of scheduled tasks awaiting processing by an event loop.
- callbackuses · A callback is a function or other callable supplied to software for invocation later in response to a specified event, condition, or point in execution.
- JavaScriptused by · JavaScript is a high-level, dynamically typed, multi-paradigm programming language standardized as ECMAScript and used for web and general-purpose programming.
- eventuses · An event is an occurrence, change, or associated record or notification recognized as significant within a system or context.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.










