new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

FastAPI · all subjects

async/concurrency

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Concurrency definition: asynchronous code allowing multiple tasks

Asynchronous code allows the program to pause execution at wait points (like I/O operations) and switch to other work, rather than blocking. This enables the program to handle multiple tasks concurrently without dedicating a separate processor to each.

I/O bound operations suited for async

I/O operations that are relatively slow compared to CPU speed include: data transfer through the network, file system reads/writes, remote API calls, database operations and queries, and waiting for client data. These are called I/O bound operations and are ideal for asynchronous code.

Concurrency vs parallelism distinction

Concurrency means different tasks can pause and resume with execution interleaved, allowing a single processor to switch between tasks. Parallelism means different tasks execute simultaneously on multiple processors. Concurrency is better for I/O-bound work; parallelism is better for CPU-bound work like computation, image processing, or machine learning.

Coroutine definition and properties

A coroutine is the object returned by an `async def` function. Python recognizes it as something that can start and end but may be paused internally whenever an `await` is encountered. Coroutines are the foundation of asynchronous programming with `async` and `await`.

Web applications benefit from concurrency

Web applications have many users with not-so-good connections, causing the server to wait for requests to be sent and responses to be received. Although measured in microseconds, this waiting accumulates significantly, making asynchronous concurrency the ideal approach for web APIs.

Give your agent this brain