Files
career-progression-2026/week-01-python-internals/day-001-gil/week-01-python-internals_day-01-gil_notes.md
2026-03-14 16:37:03 -05:00

2.5 KiB
Raw Permalink Blame History

Day 1 — GIL + CPU-bound vs I/O-bound threading

Goals (what "done" means)

  • I can explain the GIL in 23 sentences and why it impacts CPU-bound threading more than I/O-bound threading.
  • I can choose between threads, processes, and asyncio for a given workload and justify it.
  • I have benchmark results (numbers) that demonstrate the above.

Reading (mostly)

Hands-on (benchmark + notes)

  • Create a benchmark script that compares these variants for a CPU-bound function:
    • Serial (single process, no threads)
    • ThreadPoolExecutor
    • ProcessPoolExecutor
  • Use a repeatable timing method (pick one):
    • timeit (preferred for small benchmarks): timeit — Python docs
    • or wall-clock timing with time.perf_counter() (fine for longer tasks)
  • Record results in a small table (example format):
    • workload size parameters (so you can reproduce)
    • runtime for each approach
    • notes on CPU utilization / behavior
  • Add an I/O-bound comparison:
    • Serial loop calling time.sleep(x)
    • Thread pool version (expect improvement)
  • Write "Conclusions" (minimum 6 sentences):
    • What happened for CPU-bound?
    • What happened for I/O-bound?
    • What I would choose in real systems and why

Stretch (optional)

Deliverables (to commit)

  • notes.md updated with:
    • explanation bullets
    • benchmark table
    • conclusions
  • benchmark.py (or similar) added with instructions to run

Suggested commits

  • day01: add GIL notes + benchmark scaffolding
  • day01: record CPU vs IO benchmark results and conclusions