parallelazy 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. parallelazy-0.2.1/PKG-INFO +294 -0
  2. parallelazy-0.2.1/README.md +267 -0
  3. parallelazy-0.2.1/parallelazy/SKILL.md +143 -0
  4. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/__init__.py +8 -0
  5. parallelazy-0.2.1/parallelazy/__main__.py +78 -0
  6. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin_manager.py +44 -12
  7. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin_monitor.py +135 -6
  8. parallelazy-0.2.1/parallelazy.egg-info/PKG-INFO +294 -0
  9. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy.egg-info/SOURCES.txt +3 -0
  10. {parallelazy-0.2.0 → parallelazy-0.2.1}/pyproject.toml +5 -2
  11. parallelazy-0.2.1/tests/test_agent_guide.py +70 -0
  12. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_plugin_monitoring.py +133 -1
  13. parallelazy-0.2.0/PKG-INFO +0 -124
  14. parallelazy-0.2.0/README.md +0 -97
  15. parallelazy-0.2.0/parallelazy.egg-info/PKG-INFO +0 -124
  16. {parallelazy-0.2.0 → parallelazy-0.2.1}/LICENSE +0 -0
  17. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/environment_manager.py +0 -0
  18. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin.py +0 -0
  19. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin_data.py +0 -0
  20. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin_logging.py +0 -0
  21. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin_rpc.py +0 -0
  22. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin_transport.py +0 -0
  23. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/plugin_worker.py +0 -0
  24. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy/utils.py +0 -0
  25. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy.egg-info/dependency_links.txt +0 -0
  26. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy.egg-info/requires.txt +0 -0
  27. {parallelazy-0.2.0 → parallelazy-0.2.1}/parallelazy.egg-info/top_level.txt +0 -0
  28. {parallelazy-0.2.0 → parallelazy-0.2.1}/setup.cfg +0 -0
  29. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_api_env.py +0 -0
  30. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_api_ipc_transport.py +0 -0
  31. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_api_lifecycle.py +0 -0
  32. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_api_logging_and_monitoring.py +0 -0
  33. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_api_pubsub.py +0 -0
  34. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_api_rpc_and_errors.py +0 -0
  35. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_chaos_and_resilience.py +0 -0
  36. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_plugin_lifecycle.py +0 -0
  37. {parallelazy-0.2.0 → parallelazy-0.2.1}/tests/test_plugin_logging.py +0 -0
@@ -0,0 +1,294 @@
1
+ Metadata-Version: 2.4
2
+ Name: parallelazy
3
+ Version: 0.2.1
4
+ Summary: A lightweight multiprocess worker-plugin framework. Topic-based pub/sub, global environment, using process spawn and pipes, PyTorch and CUDA ready.
5
+ Author: Cesare Montresor
6
+ License-Expression: GPL-2.0-only
7
+ Project-URL: Homepage, https://github.com/cesare-montresor/parallelazy
8
+ Project-URL: Repository, https://github.com/cesare-montresor/parallelazy
9
+ Project-URL: Issues, https://github.com/cesare-montresor/parallelazy/issues
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: torch
22
+ Requires-Dist: numpy
23
+ Provides-Extra: monitoring
24
+ Requires-Dist: psutil; extra == "monitoring"
25
+ Requires-Dist: nvidia-ml-py; extra == "monitoring"
26
+ Dynamic: license-file
27
+
28
+ <div align="center">
29
+
30
+ <img src="https://raw.githubusercontent.com/cesare-montresor/parallelazy/main/icon.jpg" alt="parallelazy logo" width="140" style="border-radius: 24px;" />
31
+
32
+ # parallelazy
33
+
34
+ **Lightweight multiprocess plugin pipelines for Python — spawn-isolated workers, pipe-backed pub/sub, shared environment, RPC, and PyTorch/CUDA-aware IPC.**
35
+
36
+ [![PyPI version](https://img.shields.io/pypi/v/parallelazy?color=blue&logo=pypi&logoColor=white)](https://pypi.org/project/parallelazy/)
37
+ [![Python versions](https://img.shields.io/pypi/pyversions/parallelazy?logo=python&logoColor=white)](https://pypi.org/project/parallelazy/)
38
+ [![PyPI downloads](https://img.shields.io/pypi/dm/parallelazy?color=brightgreen)](https://pypi.org/project/parallelazy/)
39
+ [![PyTorch CUDA IPC](https://img.shields.io/badge/PyTorch-CUDA%20IPC-EE4C2C?logo=pytorch&logoColor=white)](https://github.com/cesare-montresor/parallelazy/blob/main/examples/example_cuda_zero_copy.py)
40
+ [![VS Code Debugger](https://img.shields.io/visual-studio-marketplace/v/CesareMontresor.parallelazy-vscode?label=VS%20Code%20Debugger&logo=visualstudiocode&logoColor=white)](https://marketplace.visualstudio.com/items?itemName=CesareMontresor.parallelazy-vscode)
41
+ [![License](https://img.shields.io/github/license/cesare-montresor/parallelazy)](https://github.com/cesare-montresor/parallelazy/blob/main/LICENSE)
42
+
43
+ [Features](#features) · [Installation](#installation) · [Quick Start](#quick-start) · [Monitoring](#pipeline-monitoring) · [VS Code Debugging](#debugging-in-vs-code) · [AI Agents](#using-with-ai-agents) · [Examples](#examples) · [Docs](https://github.com/cesare-montresor/parallelazy/blob/main/docs/index.md)
44
+
45
+ </div>
46
+
47
+ ---
48
+
49
+ ## Why `parallelazy`?
50
+
51
+ Building multi-process Python pipelines—especially for ML, computer vision, and PyTorch/CUDA workloads—usually means writing boilerplate around `multiprocessing.Queue`, wrestling with shutdown races, debugging broken `spawn` workers, and tracking down tensor IPC leaks.
52
+
53
+ **`parallelazy`** gives you a clean, zero-broker plugin architecture built on `torch.multiprocessing` (`spawn`). Each stage runs in its own isolated OS process with deterministic lifecycle hooks, direct pipe-backed pub/sub, a shared reactive environment, plugin-to-plugin RPC, and built-in observability.
54
+
55
+ ## Features
56
+
57
+ | | Capability | Details |
58
+ | :-: | :--- | :--- |
59
+ | 🧩 | **Spawn-Isolated Plugins** | Separate `load` → `start` → `stop` → `unload` lifecycle, parallel plugin loading, cooperative `wait_for_stop()`, and JSON-serializable `Plugin.Descriptor`s. |
60
+ | 📡 | **Live Topic Pub/Sub** | Direct per-subscriber pipe-backed fan-out queues with strict pipe ownership and no external message broker. |
61
+ | 🌍 | **Shared Environment** | Manager-owned key/value store with FIFO `env_subscribe()` notifications (initial value delivered before updates) and `None`-safe `env_get()`. |
62
+ | ⚡ | **Plugin-to-Plugin RPC** | Synchronous and async (`wait=False`) method calls between plugins, plus dynamic plugin orchestration from supervisor workers. |
63
+ | 🔥 | **PyTorch & CUDA-Aware IPC** | Automatic recursive `sanitize_for_ipc()`, compiled/CUDA-graph output marking (`mark_graph_output()`), and managed CUDA event pools (`IpcEventPoolManaged`). |
64
+ | 📊 | **Read-Only Pipeline Monitor** | Inspect pending topic pipe bytes (`FIONREAD`), CPU/RAM usage (`psutil`), and NVIDIA GPU metrics (`nvidia-ml-py`) without reading payloads. |
65
+ | 📝 | **Correlated Run Logging** | Manager and worker logs share a single run ID with configurable `work_dir`/`log_dir`, or silent `write_logs=False` for tests. |
66
+ | 🐛 | **VS Code Spawn Debugging** | Auto-attach `debugpy` to spawned worker processes via the companion [parallelazy-vscode](https://marketplace.visualstudio.com/items?itemName=CesareMontresor.parallelazy-vscode) extension. |
67
+ | 🤖 | **AI Agent Ready** | Ships an embedded Agent Skill (`SKILL.md`) inside the wheel for coding assistants. |
68
+
69
+ ## Architecture at a Glance
70
+
71
+ ```mermaid
72
+ flowchart LR
73
+ subgraph Host["Host Process"]
74
+ PM["PluginManager"]
75
+ ENV["Shared Environment"]
76
+ MON["PipelineMonitor (optional)"]
77
+ PM --- ENV
78
+ PM -. read-only .-> MON
79
+ end
80
+
81
+ subgraph W1["Worker Process 1 (spawn)"]
82
+ P1["Producer Plugin"]
83
+ end
84
+
85
+ subgraph W2["Worker Process 2 (spawn)"]
86
+ P2["Consumer Plugin"]
87
+ end
88
+
89
+ PM <-->|"Lifecycle / RPC / Env"| P1
90
+ PM <-->|"Lifecycle / RPC / Env"| P2
91
+ P1 -->|"Topic Pipe (Tensors / Objects)"| P2
92
+ ```
93
+
94
+ ## Installation
95
+
96
+ Requires **Python 3.11+**, **PyTorch**, and **NumPy**.
97
+
98
+ ```bash
99
+ pip install parallelazy
100
+ ```
101
+
102
+ To enable CPU, memory, and NVIDIA GPU metrics in the built-in pipeline monitor:
103
+
104
+ ```bash
105
+ pip install "parallelazy[monitoring]"
106
+ ```
107
+
108
+ For local development from source:
109
+
110
+ ```bash
111
+ git clone https://github.com/cesare-montresor/parallelazy.git
112
+ cd parallelazy
113
+ pip install -e ".[monitoring]"
114
+ ```
115
+
116
+ ## Quick Start
117
+
118
+ ```python
119
+ import time
120
+ from parallelazy import Plugin, PluginManager
121
+
122
+
123
+ class Worker(Plugin):
124
+ @classmethod
125
+ def default_options(cls) -> dict:
126
+ return {"greeting": "hello"}
127
+
128
+ def on_start(self):
129
+ self.topic_subscribe("jobs", self.on_job)
130
+ self.env_set("worker.ready", True)
131
+
132
+ def on_job(self, payload):
133
+ self.logger.info("%s: %s", self.options["greeting"], payload)
134
+
135
+ def main(self):
136
+ # Return immediately for event-driven plugins, or loop cooperatively
137
+ # with `while not self.wait_for_stop(timeout=0.5): ...`
138
+ pass
139
+
140
+ def on_stop(self):
141
+ self.env_set("worker.ready", False)
142
+
143
+
144
+ def main():
145
+ with PluginManager() as manager:
146
+ descriptor = Worker.Descriptor(
147
+ version="1.0.0",
148
+ author="Application team",
149
+ description="Example worker",
150
+ options={"greeting": "hi"},
151
+ )
152
+ if not manager.load_plugin(descriptor):
153
+ raise RuntimeError(f"Failed to load {descriptor.name}")
154
+ if not manager.start_plugin(descriptor.name):
155
+ raise RuntimeError(f"Failed to start {descriptor.name}")
156
+
157
+ time.sleep(0.1)
158
+ print("Worker ready:", manager.env_get("worker.ready"))
159
+ manager.topic_publish("jobs", {"task_id": 1})
160
+
161
+
162
+ if __name__ == "__main__":
163
+ main()
164
+ ```
165
+
166
+ > **Note:** Because `parallelazy` uses the `spawn` start method, always guard application startup with `if __name__ == "__main__":` and keep `Plugin` subclasses at module top level in an importable module (run scripts as `python -m your_package.module`).
167
+
168
+ ## Communication & IPC Primitives
169
+
170
+ <details>
171
+ <summary><b>📡 Topic Pub/Sub</b> — live pipe-backed fan-out</summary>
172
+
173
+ ```python
174
+ # Inside a subscriber plugin (register in on_start so early messages aren't missed)
175
+ self.topic_subscribe("frames", self.on_frame)
176
+
177
+ # Inside a publisher plugin or from PluginManager
178
+ self.topic_publish("frames", {"tensor": frame_tensor, "seq": 42})
179
+ ```
180
+
181
+ </details>
182
+
183
+ <details>
184
+ <summary><b>🌍 Shared Environment</b> — manager-owned reactive state</summary>
185
+
186
+ ```python
187
+ # Set a value from any plugin or the manager
188
+ self.env_set("model.threshold", 0.75)
189
+
190
+ # Read a value (distinguishes stored None from unset keys)
191
+ threshold = self.env_get("model.threshold", default=0.5)
192
+
193
+ # React to changes in FIFO order (initial value delivered first)
194
+ self.env_subscribe("model.threshold", self.on_threshold_change)
195
+ ```
196
+
197
+ </details>
198
+
199
+ <details>
200
+ <summary><b>⚡ Plugin RPC & Dynamic Orchestration</b> — sync or async calls</summary>
201
+
202
+ ```python
203
+ # Synchronous RPC
204
+ result = self.plugin_call("feature-extractor", "infer", batch)
205
+
206
+ # Asynchronous RPC (returns a PendingRequest)
207
+ req = self.plugin_call("feature-extractor", "infer", batch, wait=False)
208
+ result = req.wait(timeout=5.0)
209
+ ```
210
+
211
+ </details>
212
+
213
+ <details>
214
+ <summary><b>🔥 PyTorch & CUDA IPC</b> — safe tensor transfer & zero-copy pools</summary>
215
+
216
+ - Plain Python objects, nested containers, NumPy arrays, and PyTorch CPU/CUDA tensors work natively across topics, environment values, and RPC.
217
+ - `sanitize_for_ipc()` automatically clones IPC-received or graph-pooled tensors before re-sharing.
218
+ - Wrap outputs from `torch.compile` or CUDA graphs with `mark_graph_output(tensor)` before publishing or returning them.
219
+ - Use `IpcEventPoolManaged` for zero-copy CUDA tensor streaming with cross-process synchronization (see [`example_cuda_zero_copy.py`](https://github.com/cesare-montresor/parallelazy/blob/main/examples/example_cuda_zero_copy.py)).
220
+
221
+ </details>
222
+
223
+ ## Pipeline Monitoring
224
+
225
+ Enable an optional, read-only view of topic backlog, plugin process resources, and shared environment activity:
226
+
227
+ ```python
228
+ manager.enable_monitoring(sample_interval=1.0)
229
+ snapshot = manager.get_monitoring_snapshot()
230
+ manager.print_monitoring_report()
231
+ manager.disable_monitoring()
232
+ ```
233
+
234
+ - **Zero payload intrusion:** the monitor never reads or mutates topic messages; topic backlog is measured as pending pipe bytes (`FIONREAD`).
235
+ - **Process & GPU telemetry:** uses `psutil` for CPU/RAM and `nvidia-ml-py` for NVIDIA GPUs when installed via `pip install "parallelazy[monitoring]"`, and clearly reports any missing optional dependency.
236
+
237
+ ## Debugging in VS Code
238
+
239
+ Because `debugpy` does not automatically attach to `spawn`-started subprocesses, `parallelazy` pairs with a lightweight companion VS Code extension:
240
+
241
+ - **Marketplace:** [CesareMontresor.parallelazy-vscode](https://marketplace.visualstudio.com/items?itemName=CesareMontresor.parallelazy-vscode)
242
+ - **How it works:** when running under the VS Code debugger, spawned workers reuse VS Code's `debugpy` path and notify the extension to attach automatically—no separately pinned `debugpy` dependency required.
243
+ - Ready-to-use launch configurations for all examples are included in [`.vscode/launch.json`](https://github.com/cesare-montresor/parallelazy/blob/main/.vscode/launch.json).
244
+
245
+ ## Using with AI Agents
246
+
247
+ `parallelazy` bundles a concise Agent Skill / usage guide (`parallelazy/SKILL.md`) right inside the wheel so coding agents immediately follow lifecycle, concurrency, and CUDA IPC best practices:
248
+
249
+ ```bash
250
+ # Print the embedded usage guide (or pass --path for the installed file path)
251
+ python -m parallelazy agent-guide
252
+
253
+ # Install as a local Agent Skill (.agents/skills/parallelazy/SKILL.md by default)
254
+ python -m parallelazy install-skill
255
+ ```
256
+
257
+ ## Examples
258
+
259
+ All runnable examples live in [`examples/`](https://github.com/cesare-montresor/parallelazy/tree/main/examples) and can be executed from the repository root with `python -m`:
260
+
261
+ | Example | Command | What It Demonstrates |
262
+ | :--- | :--- | :--- |
263
+ | **Quickstart** | `python -m examples.example_quickstart` | Lifecycle hooks, `work_dir`, custom log formats, cooperative `wait_for_stop()` |
264
+ | **Tensor Pipeline** | `python -m examples.example_tensor_pipeline` | 3-stage PyTorch pub/sub pipeline, parallel loading, live monitoring |
265
+ | **Live Config** | `python -m examples.example_live_config` | Shared environment flags, `None` vs unset keys, FIFO `env_subscribe` |
266
+ | **Dynamic Orchestrator** | `python -m examples.example_dynamic_orchestrator` | Supervisor plugin spawning workers dynamically with async RPC sharding |
267
+ | **Resilience & Errors** | `python -m examples.example_resilience_and_errors` | `on_error()`, `PluginState.ERROR`, `plugin_errors()`, retries & reload recovery |
268
+ | **CUDA Zero-Copy** | `python -m examples.example_cuda_zero_copy` | Zero-copy CUDA streaming with `IpcEventPoolManaged` and `mark_graph_output()` |
269
+
270
+ ## Documentation
271
+
272
+ | Guide | Description |
273
+ | :--- | :--- |
274
+ | [Documentation Index](https://github.com/cesare-montresor/parallelazy/blob/main/docs/index.md) | Overview and navigation for all guides |
275
+ | [Getting Started](https://github.com/cesare-montresor/parallelazy/blob/main/docs/getting-started.md) | Installation, first plugin, and setup checklist |
276
+ | [Core Concepts & Lifecycle](https://github.com/cesare-montresor/parallelazy/blob/main/docs/concepts.md) | Process model, threading, shutdown ordering, and IPC semantics |
277
+ | [API Reference](https://github.com/cesare-montresor/parallelazy/blob/main/docs/api.md) | Complete `Plugin`, `PluginManager`, IPC, and monitoring contracts |
278
+ | [Examples & Patterns](https://github.com/cesare-montresor/parallelazy/blob/main/docs/examples.md) | Walkthroughs of the bundled end-to-end pipelines |
279
+ | [Troubleshooting](https://github.com/cesare-montresor/parallelazy/blob/main/docs/troubleshooting.md) | Common `spawn`, shutdown, logging, and CUDA IPC pitfalls |
280
+ | [Pipeline Monitor Analysis](https://github.com/cesare-montresor/parallelazy/blob/main/docs/monitoring_tool_analysys.md) | Design and metrics reference for `PipelineMonitor` |
281
+
282
+ ## Development & Testing
283
+
284
+ ```bash
285
+ # Run the test suite (CUDA IPC tests skip automatically on CPU-only hosts)
286
+ python -m unittest discover -s tests
287
+
288
+ # Build sdist and wheel distributions
289
+ python -m build
290
+ ```
291
+
292
+ ## License
293
+
294
+ Distributed under the **GNU General Public License v2.0** — see [LICENSE](https://github.com/cesare-montresor/parallelazy/blob/main/LICENSE) for details. Created by [Cesare Montresor](https://github.com/cesare-montresor).
@@ -0,0 +1,267 @@
1
+ <div align="center">
2
+
3
+ <img src="https://raw.githubusercontent.com/cesare-montresor/parallelazy/main/icon.jpg" alt="parallelazy logo" width="140" style="border-radius: 24px;" />
4
+
5
+ # parallelazy
6
+
7
+ **Lightweight multiprocess plugin pipelines for Python — spawn-isolated workers, pipe-backed pub/sub, shared environment, RPC, and PyTorch/CUDA-aware IPC.**
8
+
9
+ [![PyPI version](https://img.shields.io/pypi/v/parallelazy?color=blue&logo=pypi&logoColor=white)](https://pypi.org/project/parallelazy/)
10
+ [![Python versions](https://img.shields.io/pypi/pyversions/parallelazy?logo=python&logoColor=white)](https://pypi.org/project/parallelazy/)
11
+ [![PyPI downloads](https://img.shields.io/pypi/dm/parallelazy?color=brightgreen)](https://pypi.org/project/parallelazy/)
12
+ [![PyTorch CUDA IPC](https://img.shields.io/badge/PyTorch-CUDA%20IPC-EE4C2C?logo=pytorch&logoColor=white)](https://github.com/cesare-montresor/parallelazy/blob/main/examples/example_cuda_zero_copy.py)
13
+ [![VS Code Debugger](https://img.shields.io/visual-studio-marketplace/v/CesareMontresor.parallelazy-vscode?label=VS%20Code%20Debugger&logo=visualstudiocode&logoColor=white)](https://marketplace.visualstudio.com/items?itemName=CesareMontresor.parallelazy-vscode)
14
+ [![License](https://img.shields.io/github/license/cesare-montresor/parallelazy)](https://github.com/cesare-montresor/parallelazy/blob/main/LICENSE)
15
+
16
+ [Features](#features) · [Installation](#installation) · [Quick Start](#quick-start) · [Monitoring](#pipeline-monitoring) · [VS Code Debugging](#debugging-in-vs-code) · [AI Agents](#using-with-ai-agents) · [Examples](#examples) · [Docs](https://github.com/cesare-montresor/parallelazy/blob/main/docs/index.md)
17
+
18
+ </div>
19
+
20
+ ---
21
+
22
+ ## Why `parallelazy`?
23
+
24
+ Building multi-process Python pipelines—especially for ML, computer vision, and PyTorch/CUDA workloads—usually means writing boilerplate around `multiprocessing.Queue`, wrestling with shutdown races, debugging broken `spawn` workers, and tracking down tensor IPC leaks.
25
+
26
+ **`parallelazy`** gives you a clean, zero-broker plugin architecture built on `torch.multiprocessing` (`spawn`). Each stage runs in its own isolated OS process with deterministic lifecycle hooks, direct pipe-backed pub/sub, a shared reactive environment, plugin-to-plugin RPC, and built-in observability.
27
+
28
+ ## Features
29
+
30
+ | | Capability | Details |
31
+ | :-: | :--- | :--- |
32
+ | 🧩 | **Spawn-Isolated Plugins** | Separate `load` → `start` → `stop` → `unload` lifecycle, parallel plugin loading, cooperative `wait_for_stop()`, and JSON-serializable `Plugin.Descriptor`s. |
33
+ | 📡 | **Live Topic Pub/Sub** | Direct per-subscriber pipe-backed fan-out queues with strict pipe ownership and no external message broker. |
34
+ | 🌍 | **Shared Environment** | Manager-owned key/value store with FIFO `env_subscribe()` notifications (initial value delivered before updates) and `None`-safe `env_get()`. |
35
+ | ⚡ | **Plugin-to-Plugin RPC** | Synchronous and async (`wait=False`) method calls between plugins, plus dynamic plugin orchestration from supervisor workers. |
36
+ | 🔥 | **PyTorch & CUDA-Aware IPC** | Automatic recursive `sanitize_for_ipc()`, compiled/CUDA-graph output marking (`mark_graph_output()`), and managed CUDA event pools (`IpcEventPoolManaged`). |
37
+ | 📊 | **Read-Only Pipeline Monitor** | Inspect pending topic pipe bytes (`FIONREAD`), CPU/RAM usage (`psutil`), and NVIDIA GPU metrics (`nvidia-ml-py`) without reading payloads. |
38
+ | 📝 | **Correlated Run Logging** | Manager and worker logs share a single run ID with configurable `work_dir`/`log_dir`, or silent `write_logs=False` for tests. |
39
+ | 🐛 | **VS Code Spawn Debugging** | Auto-attach `debugpy` to spawned worker processes via the companion [parallelazy-vscode](https://marketplace.visualstudio.com/items?itemName=CesareMontresor.parallelazy-vscode) extension. |
40
+ | 🤖 | **AI Agent Ready** | Ships an embedded Agent Skill (`SKILL.md`) inside the wheel for coding assistants. |
41
+
42
+ ## Architecture at a Glance
43
+
44
+ ```mermaid
45
+ flowchart LR
46
+ subgraph Host["Host Process"]
47
+ PM["PluginManager"]
48
+ ENV["Shared Environment"]
49
+ MON["PipelineMonitor (optional)"]
50
+ PM --- ENV
51
+ PM -. read-only .-> MON
52
+ end
53
+
54
+ subgraph W1["Worker Process 1 (spawn)"]
55
+ P1["Producer Plugin"]
56
+ end
57
+
58
+ subgraph W2["Worker Process 2 (spawn)"]
59
+ P2["Consumer Plugin"]
60
+ end
61
+
62
+ PM <-->|"Lifecycle / RPC / Env"| P1
63
+ PM <-->|"Lifecycle / RPC / Env"| P2
64
+ P1 -->|"Topic Pipe (Tensors / Objects)"| P2
65
+ ```
66
+
67
+ ## Installation
68
+
69
+ Requires **Python 3.11+**, **PyTorch**, and **NumPy**.
70
+
71
+ ```bash
72
+ pip install parallelazy
73
+ ```
74
+
75
+ To enable CPU, memory, and NVIDIA GPU metrics in the built-in pipeline monitor:
76
+
77
+ ```bash
78
+ pip install "parallelazy[monitoring]"
79
+ ```
80
+
81
+ For local development from source:
82
+
83
+ ```bash
84
+ git clone https://github.com/cesare-montresor/parallelazy.git
85
+ cd parallelazy
86
+ pip install -e ".[monitoring]"
87
+ ```
88
+
89
+ ## Quick Start
90
+
91
+ ```python
92
+ import time
93
+ from parallelazy import Plugin, PluginManager
94
+
95
+
96
+ class Worker(Plugin):
97
+ @classmethod
98
+ def default_options(cls) -> dict:
99
+ return {"greeting": "hello"}
100
+
101
+ def on_start(self):
102
+ self.topic_subscribe("jobs", self.on_job)
103
+ self.env_set("worker.ready", True)
104
+
105
+ def on_job(self, payload):
106
+ self.logger.info("%s: %s", self.options["greeting"], payload)
107
+
108
+ def main(self):
109
+ # Return immediately for event-driven plugins, or loop cooperatively
110
+ # with `while not self.wait_for_stop(timeout=0.5): ...`
111
+ pass
112
+
113
+ def on_stop(self):
114
+ self.env_set("worker.ready", False)
115
+
116
+
117
+ def main():
118
+ with PluginManager() as manager:
119
+ descriptor = Worker.Descriptor(
120
+ version="1.0.0",
121
+ author="Application team",
122
+ description="Example worker",
123
+ options={"greeting": "hi"},
124
+ )
125
+ if not manager.load_plugin(descriptor):
126
+ raise RuntimeError(f"Failed to load {descriptor.name}")
127
+ if not manager.start_plugin(descriptor.name):
128
+ raise RuntimeError(f"Failed to start {descriptor.name}")
129
+
130
+ time.sleep(0.1)
131
+ print("Worker ready:", manager.env_get("worker.ready"))
132
+ manager.topic_publish("jobs", {"task_id": 1})
133
+
134
+
135
+ if __name__ == "__main__":
136
+ main()
137
+ ```
138
+
139
+ > **Note:** Because `parallelazy` uses the `spawn` start method, always guard application startup with `if __name__ == "__main__":` and keep `Plugin` subclasses at module top level in an importable module (run scripts as `python -m your_package.module`).
140
+
141
+ ## Communication & IPC Primitives
142
+
143
+ <details>
144
+ <summary><b>📡 Topic Pub/Sub</b> — live pipe-backed fan-out</summary>
145
+
146
+ ```python
147
+ # Inside a subscriber plugin (register in on_start so early messages aren't missed)
148
+ self.topic_subscribe("frames", self.on_frame)
149
+
150
+ # Inside a publisher plugin or from PluginManager
151
+ self.topic_publish("frames", {"tensor": frame_tensor, "seq": 42})
152
+ ```
153
+
154
+ </details>
155
+
156
+ <details>
157
+ <summary><b>🌍 Shared Environment</b> — manager-owned reactive state</summary>
158
+
159
+ ```python
160
+ # Set a value from any plugin or the manager
161
+ self.env_set("model.threshold", 0.75)
162
+
163
+ # Read a value (distinguishes stored None from unset keys)
164
+ threshold = self.env_get("model.threshold", default=0.5)
165
+
166
+ # React to changes in FIFO order (initial value delivered first)
167
+ self.env_subscribe("model.threshold", self.on_threshold_change)
168
+ ```
169
+
170
+ </details>
171
+
172
+ <details>
173
+ <summary><b>⚡ Plugin RPC & Dynamic Orchestration</b> — sync or async calls</summary>
174
+
175
+ ```python
176
+ # Synchronous RPC
177
+ result = self.plugin_call("feature-extractor", "infer", batch)
178
+
179
+ # Asynchronous RPC (returns a PendingRequest)
180
+ req = self.plugin_call("feature-extractor", "infer", batch, wait=False)
181
+ result = req.wait(timeout=5.0)
182
+ ```
183
+
184
+ </details>
185
+
186
+ <details>
187
+ <summary><b>🔥 PyTorch & CUDA IPC</b> — safe tensor transfer & zero-copy pools</summary>
188
+
189
+ - Plain Python objects, nested containers, NumPy arrays, and PyTorch CPU/CUDA tensors work natively across topics, environment values, and RPC.
190
+ - `sanitize_for_ipc()` automatically clones IPC-received or graph-pooled tensors before re-sharing.
191
+ - Wrap outputs from `torch.compile` or CUDA graphs with `mark_graph_output(tensor)` before publishing or returning them.
192
+ - Use `IpcEventPoolManaged` for zero-copy CUDA tensor streaming with cross-process synchronization (see [`example_cuda_zero_copy.py`](https://github.com/cesare-montresor/parallelazy/blob/main/examples/example_cuda_zero_copy.py)).
193
+
194
+ </details>
195
+
196
+ ## Pipeline Monitoring
197
+
198
+ Enable an optional, read-only view of topic backlog, plugin process resources, and shared environment activity:
199
+
200
+ ```python
201
+ manager.enable_monitoring(sample_interval=1.0)
202
+ snapshot = manager.get_monitoring_snapshot()
203
+ manager.print_monitoring_report()
204
+ manager.disable_monitoring()
205
+ ```
206
+
207
+ - **Zero payload intrusion:** the monitor never reads or mutates topic messages; topic backlog is measured as pending pipe bytes (`FIONREAD`).
208
+ - **Process & GPU telemetry:** uses `psutil` for CPU/RAM and `nvidia-ml-py` for NVIDIA GPUs when installed via `pip install "parallelazy[monitoring]"`, and clearly reports any missing optional dependency.
209
+
210
+ ## Debugging in VS Code
211
+
212
+ Because `debugpy` does not automatically attach to `spawn`-started subprocesses, `parallelazy` pairs with a lightweight companion VS Code extension:
213
+
214
+ - **Marketplace:** [CesareMontresor.parallelazy-vscode](https://marketplace.visualstudio.com/items?itemName=CesareMontresor.parallelazy-vscode)
215
+ - **How it works:** when running under the VS Code debugger, spawned workers reuse VS Code's `debugpy` path and notify the extension to attach automatically—no separately pinned `debugpy` dependency required.
216
+ - Ready-to-use launch configurations for all examples are included in [`.vscode/launch.json`](https://github.com/cesare-montresor/parallelazy/blob/main/.vscode/launch.json).
217
+
218
+ ## Using with AI Agents
219
+
220
+ `parallelazy` bundles a concise Agent Skill / usage guide (`parallelazy/SKILL.md`) right inside the wheel so coding agents immediately follow lifecycle, concurrency, and CUDA IPC best practices:
221
+
222
+ ```bash
223
+ # Print the embedded usage guide (or pass --path for the installed file path)
224
+ python -m parallelazy agent-guide
225
+
226
+ # Install as a local Agent Skill (.agents/skills/parallelazy/SKILL.md by default)
227
+ python -m parallelazy install-skill
228
+ ```
229
+
230
+ ## Examples
231
+
232
+ All runnable examples live in [`examples/`](https://github.com/cesare-montresor/parallelazy/tree/main/examples) and can be executed from the repository root with `python -m`:
233
+
234
+ | Example | Command | What It Demonstrates |
235
+ | :--- | :--- | :--- |
236
+ | **Quickstart** | `python -m examples.example_quickstart` | Lifecycle hooks, `work_dir`, custom log formats, cooperative `wait_for_stop()` |
237
+ | **Tensor Pipeline** | `python -m examples.example_tensor_pipeline` | 3-stage PyTorch pub/sub pipeline, parallel loading, live monitoring |
238
+ | **Live Config** | `python -m examples.example_live_config` | Shared environment flags, `None` vs unset keys, FIFO `env_subscribe` |
239
+ | **Dynamic Orchestrator** | `python -m examples.example_dynamic_orchestrator` | Supervisor plugin spawning workers dynamically with async RPC sharding |
240
+ | **Resilience & Errors** | `python -m examples.example_resilience_and_errors` | `on_error()`, `PluginState.ERROR`, `plugin_errors()`, retries & reload recovery |
241
+ | **CUDA Zero-Copy** | `python -m examples.example_cuda_zero_copy` | Zero-copy CUDA streaming with `IpcEventPoolManaged` and `mark_graph_output()` |
242
+
243
+ ## Documentation
244
+
245
+ | Guide | Description |
246
+ | :--- | :--- |
247
+ | [Documentation Index](https://github.com/cesare-montresor/parallelazy/blob/main/docs/index.md) | Overview and navigation for all guides |
248
+ | [Getting Started](https://github.com/cesare-montresor/parallelazy/blob/main/docs/getting-started.md) | Installation, first plugin, and setup checklist |
249
+ | [Core Concepts & Lifecycle](https://github.com/cesare-montresor/parallelazy/blob/main/docs/concepts.md) | Process model, threading, shutdown ordering, and IPC semantics |
250
+ | [API Reference](https://github.com/cesare-montresor/parallelazy/blob/main/docs/api.md) | Complete `Plugin`, `PluginManager`, IPC, and monitoring contracts |
251
+ | [Examples & Patterns](https://github.com/cesare-montresor/parallelazy/blob/main/docs/examples.md) | Walkthroughs of the bundled end-to-end pipelines |
252
+ | [Troubleshooting](https://github.com/cesare-montresor/parallelazy/blob/main/docs/troubleshooting.md) | Common `spawn`, shutdown, logging, and CUDA IPC pitfalls |
253
+ | [Pipeline Monitor Analysis](https://github.com/cesare-montresor/parallelazy/blob/main/docs/monitoring_tool_analysys.md) | Design and metrics reference for `PipelineMonitor` |
254
+
255
+ ## Development & Testing
256
+
257
+ ```bash
258
+ # Run the test suite (CUDA IPC tests skip automatically on CPU-only hosts)
259
+ python -m unittest discover -s tests
260
+
261
+ # Build sdist and wheel distributions
262
+ python -m build
263
+ ```
264
+
265
+ ## License
266
+
267
+ Distributed under the **GNU General Public License v2.0** — see [LICENSE](https://github.com/cesare-montresor/parallelazy/blob/main/LICENSE) for details. Created by [Cesare Montresor](https://github.com/cesare-montresor).