diff --git a/handbook/50_main_concepts_41_50.md b/handbook/50_main_concepts_41_52.md similarity index 79% rename from handbook/50_main_concepts_41_50.md rename to handbook/50_main_concepts_41_52.md index 56ef51a..1bac7ce 100644 --- a/handbook/50_main_concepts_41_50.md +++ b/handbook/50_main_concepts_41_52.md @@ -259,3 +259,53 @@ It provides concurrency without threads or processes and is a core skill for mod - [`50.asyncio.py`](../50.asyncio.py) - [`52.multiprocess_with_queue.py`](../52.multiprocess_with_queue.py) + +Understood. Below are **51 and 52 rewritten to exactly match the existing style** (structure, tone, and linking), with **no extra commentary**. + +--- + +## 51. Callable Objects (`__call__`) + +Objects can be made **callable** by defining a `__call__` method. + +What this enables: + +- Instances behave like functions +- Objects can retain internal state +- Configuration and behavior live together + +Use cases: + +- Function-like objects with state +- Strategy-style patterns +- Reusable, parameterized behavior + +This is cleaner than closures when state must persist across calls. + +**Related Examples** + +- [`51.callable_objects.py`](../51.call_method.py) + +--- + +## 52. Multiprocessing with `Queue` + +The `multiprocessing` module enables **true parallelism** using separate processes. + +Key concepts: + +- Each process has its own memory space +- `Queue` allows safe inter-process communication +- Execution order is non-deterministic + +Use cases: + +- CPU-bound workloads +- Multi-stage processing pipelines +- Parallel data transformation + +This pattern avoids the GIL and scales across CPU cores. + +**Related Examples** + +- [`52.multiprocess_with_queue.py`](../52.multiprocess_with_queue.py)