parallelazy 0.1.1__tar.gz → 0.1.2__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 (25) hide show
  1. {parallelazy-0.1.1 → parallelazy-0.1.2}/PKG-INFO +18 -1
  2. {parallelazy-0.1.1 → parallelazy-0.1.2}/README.md +17 -0
  3. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/__init__.py +17 -0
  4. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/environment_manager.py +34 -0
  5. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/plugin_manager.py +92 -3
  6. parallelazy-0.1.2/parallelazy/plugin_monitor.py +725 -0
  7. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy.egg-info/PKG-INFO +18 -1
  8. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy.egg-info/SOURCES.txt +3 -1
  9. {parallelazy-0.1.1 → parallelazy-0.1.2}/pyproject.toml +1 -1
  10. parallelazy-0.1.2/tests/test_plugin_monitoring.py +276 -0
  11. {parallelazy-0.1.1 → parallelazy-0.1.2}/LICENSE +0 -0
  12. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/plugin.py +0 -0
  13. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/plugin_data.py +0 -0
  14. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/plugin_logging.py +0 -0
  15. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/plugin_rpc.py +0 -0
  16. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/plugin_transport.py +0 -0
  17. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/plugin_worker.py +0 -0
  18. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy/utils.py +0 -0
  19. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy.egg-info/dependency_links.txt +0 -0
  20. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy.egg-info/requires.txt +0 -0
  21. {parallelazy-0.1.1 → parallelazy-0.1.2}/parallelazy.egg-info/top_level.txt +0 -0
  22. {parallelazy-0.1.1 → parallelazy-0.1.2}/setup.cfg +0 -0
  23. {parallelazy-0.1.1 → parallelazy-0.1.2}/tests/test_env_cuda_ipc.py +0 -0
  24. {parallelazy-0.1.1 → parallelazy-0.1.2}/tests/test_plugin_lifecycle.py +0 -0
  25. {parallelazy-0.1.1 → parallelazy-0.1.2}/tests/test_plugin_logging.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: parallelazy
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: A lightweight multiprocess worker-plugin framework. Topic-based pub/sub, global enviroment, using process spawn and pipes, pytorch and CUDA ready.
5
5
  Author: Cesare Montresor
6
6
  Project-URL: Homepage, https://github.com/cesare-montresor/parallelazy
@@ -81,6 +81,23 @@ if __name__ == "__main__":
81
81
  main()
82
82
  ```
83
83
 
84
+ ## Pipeline monitoring
85
+
86
+ Enable an optional read-only view of topic backlog, plugin process resources,
87
+ and shared environment activity:
88
+
89
+ ```python
90
+ manager.enable_monitoring(sample_interval=1.0)
91
+ snapshot = manager.get_monitoring_snapshot()
92
+ manager.print_monitoring_report()
93
+ manager.disable_monitoring()
94
+ ```
95
+
96
+ The monitor never reads or changes topic payloads. Topic backlog is reported as
97
+ pending pipe bytes. Process metrics use `psutil` when installed, and NVIDIA GPU
98
+ metrics use `nvidia-ml-py`; missing optional dependencies are identified with
99
+ their install command.
100
+
84
101
  ## Documentation
85
102
 
86
103
  Read the [documentation index](docs/index.md) for installation, concepts,
@@ -65,6 +65,23 @@ if __name__ == "__main__":
65
65
  main()
66
66
  ```
67
67
 
68
+ ## Pipeline monitoring
69
+
70
+ Enable an optional read-only view of topic backlog, plugin process resources,
71
+ and shared environment activity:
72
+
73
+ ```python
74
+ manager.enable_monitoring(sample_interval=1.0)
75
+ snapshot = manager.get_monitoring_snapshot()
76
+ manager.print_monitoring_report()
77
+ manager.disable_monitoring()
78
+ ```
79
+
80
+ The monitor never reads or changes topic payloads. Topic backlog is reported as
81
+ pending pipe bytes. Process metrics use `psutil` when installed, and NVIDIA GPU
82
+ metrics use `nvidia-ml-py`; missing optional dependencies are identified with
83
+ their install command.
84
+
68
85
  ## Documentation
69
86
 
70
87
  Read the [documentation index](docs/index.md) for installation, concepts,
@@ -66,6 +66,16 @@ from parallelazy.plugin_transport import (
66
66
  mark_graph_output,
67
67
  sanitize_for_ipc,
68
68
  )
69
+ from parallelazy.utils import is_debugpy_attached
70
+ from parallelazy.plugin_monitor import (
71
+ CapabilityAvailability,
72
+ EnvironmentMetric,
73
+ MonitoringSnapshot,
74
+ PipelineMonitor,
75
+ ProcessMetric,
76
+ TopicMetric,
77
+ )
78
+
69
79
  from parallelazy.plugin_worker import PluginWorker
70
80
 
71
81
  __all__ = [
@@ -119,4 +129,11 @@ __all__ = [
119
129
  "IpcEventPoolManaged",
120
130
  "mark_graph_output",
121
131
  "sanitize_for_ipc",
132
+ "is_debugpy_attached",
133
+ "CapabilityAvailability",
134
+ "EnvironmentMetric",
135
+ "MonitoringSnapshot",
136
+ "PipelineMonitor",
137
+ "ProcessMetric",
138
+ "TopicMetric",
122
139
  ]
@@ -8,6 +8,7 @@ and broadcasting updates to interested plugins.
8
8
  from typing import Any, Dict
9
9
  from threading import Lock
10
10
  import logging
11
+ import time
11
12
 
12
13
  logger = logging.getLogger(__name__)
13
14
 
@@ -20,6 +21,9 @@ class EnvironmentManager:
20
21
  """Initialize environment manager."""
21
22
  self._env: Dict[str, Any] = {}
22
23
  self._lock = Lock()
24
+ self._monitoring_enabled = False
25
+ self._write_counts: Dict[str, int] = {}
26
+ self._last_write_times: Dict[str, float] = {}
23
27
 
24
28
  def get(self, key: str, default: Any = None) -> Any:
25
29
  """Get environment variable value."""
@@ -30,6 +34,36 @@ class EnvironmentManager:
30
34
  """Set environment variable."""
31
35
  with self._lock:
32
36
  self._env[key] = value
37
+ if self._monitoring_enabled:
38
+ self._write_counts[key] = self._write_counts.get(key, 0) + 1
39
+ self._last_write_times[key] = time.monotonic()
40
+
41
+ def begin_monitoring(self) -> None:
42
+ """Start collecting environment write counters."""
43
+ with self._lock:
44
+ self._monitoring_enabled = True
45
+ self._write_counts = {key: 0 for key in self._env}
46
+ self._last_write_times = {}
47
+
48
+ def end_monitoring(self) -> None:
49
+ """Stop collecting environment write counters."""
50
+ with self._lock:
51
+ self._monitoring_enabled = False
52
+ self._write_counts = {}
53
+ self._last_write_times = {}
54
+
55
+ def monitoring_snapshot(self) -> Dict[str, Dict[str, Any]]:
56
+ """Return environment metadata and write counters without values."""
57
+ with self._lock:
58
+ return {
59
+ key: {
60
+ "type": type(value).__name__,
61
+ "stored_size": __import__("sys").getsizeof(value),
62
+ "write_count": self._write_counts.get(key, 0),
63
+ "last_write": self._last_write_times.get(key),
64
+ }
65
+ for key, value in self._env.items()
66
+ }
33
67
 
34
68
  def get_all(self) -> Dict[str, Any]:
35
69
  """Get all environment variables."""
@@ -104,6 +104,8 @@ class PluginManager:
104
104
  self._env_subscribers: Dict[str, List[str]] = {} # env_key -> [plugin_id, ...]
105
105
 
106
106
  self._env = EnvironmentManager()
107
+ self._monitor_lock = threading.Lock()
108
+ self._monitor = None
107
109
 
108
110
  self.timeout_request = timeout_request
109
111
  self.worker_pydebug = is_debugpy_attached()
@@ -438,6 +440,7 @@ class PluginManager:
438
440
  True if unloaded successfully
439
441
  """
440
442
  try:
443
+ self.disable_monitoring()
441
444
  if plugin_id in self._plugins:
442
445
  info = self._plugins[plugin_id]
443
446
  if info.process.is_alive() and not info.stop_confirmed:
@@ -487,10 +490,10 @@ class PluginManager:
487
490
  if publisher == plugin_id:
488
491
  del self._topic_publishers[topic]
489
492
 
490
- def start_all_plugins(self) -> None:
493
+ def start_all_plugins(self, parallel=True) -> None:
491
494
  """Start all loaded plugins."""
492
- for plugin_id in list(self._plugins.keys()):
493
- self.start_plugin(plugin_id)
495
+ ids = list(self._plugins.keys())
496
+ self.start_plugins(ids, parallel=parallel)
494
497
 
495
498
  def stop_all_plugins(self) -> None:
496
499
  """Stop all running plugins."""
@@ -500,6 +503,7 @@ class PluginManager:
500
503
 
501
504
  def unload_all_plugins(self) -> None:
502
505
  """Shut down the plugin manager and all plugins."""
506
+ self.disable_monitoring()
503
507
  self.stop_all_plugins()
504
508
  for plugin_id in list(self._plugins.keys()):
505
509
  self.unload_plugin(plugin_id)
@@ -564,6 +568,91 @@ class PluginManager:
564
568
  def plugin_list(self) -> List[str]:
565
569
  """List all loaded plugin IDs."""
566
570
  return list(self._plugins.keys())
571
+
572
+ def enable_monitoring(
573
+ self,
574
+ sample_interval: float = 1.0,
575
+ ):
576
+ """Enable optional, read-only pipeline monitoring."""
577
+ from parallelazy.plugin_monitor import MonitoringAdapter, PipelineMonitor
578
+
579
+ if isinstance(sample_interval, bool) or not isinstance(sample_interval, (int, float)):
580
+ raise TypeError("sample_interval must be a number")
581
+ if sample_interval <= 0:
582
+ raise ValueError("sample_interval must be greater than zero")
583
+
584
+ with self._monitor_lock:
585
+ if self._monitor is not None:
586
+ self._monitor.start()
587
+ return self._monitor
588
+
589
+ monitor = PipelineMonitor(
590
+ MonitoringAdapter(self),
591
+ sample_interval=sample_interval,
592
+ logger=self.logger,
593
+ )
594
+ self._monitor = monitor
595
+
596
+ self._env.begin_monitoring()
597
+ monitor.start()
598
+ return monitor
599
+
600
+ def disable_monitoring(self) -> None:
601
+ """Synchronously stop pipeline monitoring."""
602
+ with self._monitor_lock:
603
+ monitor = self._monitor
604
+ if monitor is not None:
605
+ monitor.stop()
606
+ self._env.end_monitoring()
607
+ with self._monitor_lock:
608
+ self._monitor = None
609
+
610
+ def get_monitoring_snapshot(self):
611
+ """Return a point-in-time monitoring snapshot."""
612
+ from parallelazy.plugin_monitor import MonitoringAdapter, PipelineMonitor
613
+
614
+ with self._monitor_lock:
615
+ monitor = self._monitor
616
+ if monitor is not None:
617
+ return monitor.get_snapshot()
618
+
619
+ monitor = PipelineMonitor(
620
+ MonitoringAdapter(self),
621
+ sample_interval=1.0,
622
+ logger=self.logger,
623
+ )
624
+ return monitor.sample()
625
+
626
+ def print_monitoring_report(self) -> None:
627
+ """Print the latest monitoring snapshot without triggering a new sample."""
628
+ from parallelazy.plugin_monitor import MonitoringAdapter, PipelineMonitor
629
+
630
+ with self._monitor_lock:
631
+ monitor = self._monitor
632
+ if monitor is not None:
633
+ monitor.print_report()
634
+ return
635
+
636
+ monitor = PipelineMonitor(
637
+ MonitoringAdapter(self),
638
+ sample_interval=1.0,
639
+ logger=self.logger,
640
+ )
641
+ monitor.print_report(monitor.sample())
642
+
643
+ def enable_report_hotkey(self, key: str = "m") -> bool:
644
+ """Enable a hotkey that prints monitoring reports in an interactive TTY."""
645
+ monitor = self._monitor
646
+ if monitor is None:
647
+ monitor = self.enable_monitoring()
648
+ return monitor.start_hotkey(key)
649
+
650
+ def disable_report_hotkey(self) -> None:
651
+ """Disable the report hotkey and restore terminal input state."""
652
+ with self._monitor_lock:
653
+ monitor = self._monitor
654
+ if monitor is not None:
655
+ monitor.stop_hotkey()
567
656
 
568
657
 
569
658