π§
Senior Deep-Dives L5 PRO Β· 161 lessons asyncio internals, GIL, typing tricks, Rust extensions
161 lessons across 6 modules: concurrency & async internals, CPython internals & performance, metaclasses + descriptors + dunder magic, memory + profiling + optimization (memray/tracemalloc), and architecture + code review + senior judgment.
β
Before you start
Β· 2+ years of Python in production. You've shipped something that failed at 2am Β· Comfortable with type hints, dataclasses, async/await. We go into asyncio internals β not basics Β· You've read profiler output once and felt confused. Good β that's what we fix βΉοΈ Heads-up on the format: Senior Deep-Dives are mostly concept lessons + code reviews + predict-the-output exercises. Some samples touch CPython internals or C-extension boundaries that Skulpt/Pyodide can't execute β those run as walkthroughs, not live-runnable code.
πΊ Map π Curriculum
π asyncio: event loop deep-dive
π Typing: TypeVar, Generic, Protocol
π Memory and reference counting
π Profiling: cProfile, py-spy, memory_profiler
π concurrent.futures vs asyncio vs threading
π Packaging modern Python apps
π Testing strategies at scale
π Observability: metrics, traces, logs
π API design β pagination, errors, versioning
π Capstone: redesign a hot path
π The dis module β reading Python bytecode
π Slots optimization in depth
π Weak references (weakref module)
π functools.singledispatch β type-dispatch
π contextlib.contextmanager
π π― Review: Senior Python module 1 recap
π ExitStack for dynamic context management
π asyncio.TaskGroup (Python 3.11+) vs gather
π Cancellation patterns in asyncio
π asyncio.Semaphore for backpressure
π trio vs asyncio β when to pick which
π Cython basics β typing hot paths
π mypy strict mode + custom plugins
π ParamSpec and Concatenate (typing 3.10+)
π Generic protocols (typing.Protocol with TypeVar)
π Memory views and buffer protocol
π struct module for binary parsing
π logging filters and adapters
π Building custom pytest plugins
π Debugging deadlocks (py-spy + gdb)
π Capstone: profile + optimize a real bottleneck (CPU + memory)
π CPython internals: bytecode and frame objects
π PEP 703: no-GIL Python β what changes
π Faster CPython: 3.11 / 3.12 / 3.13 improvements
π Sub-interpreters (PEP 684, PEP 734)
π asyncio internals: event loop step-by-step
π π― Review: Senior Python module 2 recap
π uvloop vs default asyncio loop
π Trio's structured concurrency principles
π Multiprocessing pitfalls: pickle, fork vs spawn
π NumPy vectorization patterns
π Numba JIT for hot Python loops
π PEP 695: Type Parameters syntax (Python 3.12)
π Variadic generics: TypeVarTuple and Unpack
π typing.Self and @override (3.11+)
π dataclass slots and kw_only
π attrs vs dataclass vs Pydantic β when each wins
π msgspec for ultra-fast (de)serialization
π pydantic_settings for typed env config
π Logging at scale: structlog + sampling + sinks
π Open Source contribution flow
π Capstone: redesign a slow Python service end-to-end
π Cython basics β when pure Python isn't enough
π C extensions via ctypes / cffi
π PyO3 β Rust extensions for modern Python
π AST manipulation with the `ast` module
π Predict: bytecode introspection with `dis`
π π― Review: Senior Python module 3 recap
π Coroutine internals β `__await__` from scratch
π asyncio TaskGroups + ExceptionGroup (3.11+)
π Subinterpreters + free-threading (PEP 684, 703)
π Memory views and the buffer protocol
π Weak references and finalizers
π GC tuning β generations and freeze
π Profilers: cProfile vs pyinstrument vs py-spy
π Memory profiling: tracemalloc + memray
π Bytecode caching β __pycache__ internals
π Import system internals β finders and loaders
π Pattern matching internals β __match_args__
π Type system: ParamSpec, TypeVarTuple, Self
π Protocols vs ABCs vs duck typing
π π Capstone β diagnose a memory leak in production
π When to introduce an abstraction
π Code review: nitpicks vs blockers
π Refactoring: characterization tests first
π API design: stability vs ergonomics
π Naming: domain language wins
π π― Review: Senior Python module 4 recap
π Error handling: exceptions vs Result types
π Logging vs metrics vs tracing
π Migrations: expand β migrate β contract
π Concurrency: actor model vs shared memory
π Mocking: when it lies to you
π Documentation: ADRs for irreversible decisions
π Testing pyramid: unit > integration > e2e
π Logging PII: regulatory implications
π Caching: cache-aside vs read-through
π Threading: futures vs raw threads
π Generators: yield from + send
π Pickling: security warning
π Memory leaks: cycles and weakref
π Architecture: monolith vs microservices
π Senior interview signal: 'show me the postmortem'
π On-call: runbook is the contract
π Senior glue work: invisible but irreplaceable
π Tech debt: pay down with feature work
π Mentoring: review with questions, not answers
π π Final senior capstone: judgment under uncertainty
π Descriptor lookup order β data vs non-data
π C3 linearisation β predict the MRO
π contextvars in async β Task context isolation
π typing.Protocol β runtime_checkable's hidden hole
π asyncio reentrance β you can't nest `asyncio.run()`
π functools.cache β hashability is the gate
π Walrus in comprehensions β scope leak gotcha
π functools.partial vs lambda β closure timing
π dataclass field(default_factory) β the mutable-default block
π Sentinel object β distinguishing 'not passed' from 'passed None'
π __init_subclass__ β auto-registration without metaclasses
π enum.IntFlag β bitwise composition and the `in` operator
π WeakValueDictionary β caches that let GC do its job
π `__slots__` β when you're paying for `__dict__` you don't use
π contextlib.ExitStack β dynamic context-manager composition
π functools.singledispatch β type-dispatched generic functions
π @dataclass(frozen=True) + dataclasses.replace β immutable updates
π @runtime_checkable Protocol β structural typing + its blind spots
π __match_args__ β making your classes destructurable
π π Module 7 capstone: composing the seven patterns into a real design
π asyncio.Semaphore β bounded concurrency without blocking the loop
π asyncio.shield β let the inner work finish even when the outer awaiter walks away
π asyncio.as_completed β stream results as tasks finish
π asyncio.Queue β bounded backpressure between producer and consumer
π asyncio.Lock β FIFO-fair, NOT reentrant, cancellation-safe
π asyncio.Event β one-shot broadcast that stays set
π asyncio.TaskGroup β structured concurrency (3.11+) replaces gather
π π Module 8 capstone: async correctness in a real ingest pipeline
π Custom exception hierarchies β most-specific except first
π Mis-ordered except clauses β when subclass handlers become dead code
π Exception chaining: `raise X from Y` vs implicit context vs bare re-raise
π contextlib.suppress β quietly skip specific exceptions
π traceback.TracebackException β exceptions as data
π ExceptionGroup + except* β multiple failures, one raise
π Retry decorator β bounded attempts + exponential backoff + targeted catch
π π Module 9 capstone: batch CSV importer with structured error handling
π pathlib.Path β the modern alternative to os.path string-pushing
π @dataclass(kw_only=True, slots=True) β the modern senior default
π typing.Annotated β metadata that hides BEHIND the type
π enum.StrEnum β type-safe strings that serialise like strings
π typing.Self (3.11+) β fluent builders that subclass correctly
π typing.Never + assert_never β exhaustiveness checks the compiler enforces
π TypedDict + NotRequired β JSON shapes as types
π π Module 10 capstone: typed config-driven API client
π Parametrised decorators β three nested functions, not two
π Decorator stacking β TOP wraps last, runs first
π Class-based decorators β when the wrapper needs state
π functools.singledispatchmethod β type dispatch when there's a self in the way
π @contextlib.contextmanager β context managers from generators
π Descriptor protocol β the mechanic under @property and ORM columns
π typing.ParamSpec β decorators that preserve the wrapped signature
π π Module 11 capstone: designing a published decorator library
π Write: implement freeze() β a recursive hashable-converter for cache keys
π Write: merge_dicts() with conflict-resolution strategies
π Write: chunked() β yield successive batches from a sequence
π Write: unique_by() β order-preserving deduplication with a key function
Tip: click any lesson to revisit it. After your first attempt, the βShow exampleβ button reveals the full solution.