Skip to main content
🧠

Senior Deep-Dives

L5PROΒ· 161 lessons

asyncio internals, GIL, typing tricks, Rust extensions

0 / 161 Β· 0%

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

β†’ After you finish

ℹ️ 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.

⭐0/483 stars· 0% complete

Resume β†’

Prerequisites β€” what you should know before this track

The GIL β€” what it is, what it isn't

FREE

asyncio: event loop deep-dive

Typing: TypeVar, Generic, Protocol

Metaclasses

Descriptors

Memory and reference counting

Profiling: cProfile, py-spy, memory_profiler

concurrent.futures vs asyncio vs threading

Rust extensions via PyO3

Packaging modern Python apps

Testing strategies at scale

Observability: metrics, traces, logs

Production debugging

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

__slots__ deep dive

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.