Python, from Zero, for AILesson 57 of 89

Module 6 · Talking to a service: HTTP from Python, done properly

Threads, processes, and the lock that decides which one you need

In this lesson

  • 9 min read
  • 8 reading sections
  • Knowledge check
  • Lesson 9 of 11 in this chapter

This chapter’s goalWrite a client for a paid model API that reuses connections, times out, retries only what is safe to retry, walks pagination with a generator, consumes a streamed response as it arrives, runs many requests concurrently under a rate limit, validates the JSON the model returns before trusting it, and reports the cost of every call from the usage figures in the response.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch2:28Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 10Free · no account needed
Lesson steps

Two kinds of slow

A program is slow in one of two ways. It is waiting (for a server, a disk, a database) or it is computing: running your own loops and arithmetic. The tools for the two are different, and using the wrong one gives you a program that is exactly as slow as before, with extra complexity.

The previous lesson handled waiting with asyncio. This lesson covers the two other tools and the fact about Python that decides between them.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘Threads, processes, and the lock that decides which one you need’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/threads-processes-and-the-gil (Accessed: 21 November 2026).