🏗️Timeout
Also known as Request Timeout, Connection Timeout, Network Timeout
The longest a program will wait for a reply. Then it gives up.
Think of it like
It is like waiting for a friend at the park. After ten minutes, you stop waiting and go home.
Example
Jack's checkout calls a tax service with a 2-second timeout. When the service hangs, checkout shows a kind error. It does not spin forever.
Why it matters
Waiting forever ties up threads and memory. One stuck service can then bring down every service that calls it.
Definition
Example code
python
import requests
r = requests.get("https://example.com/api/rates", timeout=2)Common mistake
Key takeaways
- 1A limit on waiting. Then give up.
- 2Fail fast. Better than hanging.
- 3Pair with retries. Try again, with care.