~/talk

Context Managers

Talkat PyBay 2025 · on Saturday, 2025-10-18· [python, software-architecture]
links:none on file
slides:none on file

It's the 20th anniversary of PEP 343 and the talk shows why context managers prevent "too many open files" bugs (garbage collection can hide the problem but with blocks files reliably close), demonstrates using contextlib.contextmanager (generator + yield with try/finally) to build enter/exit logic, lists real uses — redirecting stdout, lock/transaction handling, timing, Trio nurseries — and explains making global-like state async-safe with contextvars (log-prefix example uses set/reset and works under concurrent tasks).

AI-written summary · about

  1. 0:00Introduction and setup
  2. 1:31Context managers in 2025
  3. 3:57Why context managers matter
  4. 6:01How context managers work
  5. 9:38Understanding the protocol
  6. 10:20Practical examples
  7. 12:05Functions twice as cool
  8. 15:37Creating context managers
  9. 17:28Scope and naming confusion
  10. 20:29Global state and context vars
  11. 24:02Context vars in depth
  12. 24:46Conclusion and Q&A
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.