parallelazy 0.1.2__tar.gz → 0.1.3__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.
- {parallelazy-0.1.2 → parallelazy-0.1.3}/PKG-INFO +4 -3
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin.py +3 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin_data.py +15 -1
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin_logging.py +43 -15
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin_manager.py +322 -124
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin_monitor.py +1 -1
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin_rpc.py +2 -2
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin_worker.py +70 -31
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy.egg-info/PKG-INFO +4 -3
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy.egg-info/requires.txt +3 -1
- {parallelazy-0.1.2 → parallelazy-0.1.3}/pyproject.toml +5 -3
- {parallelazy-0.1.2 → parallelazy-0.1.3}/tests/test_plugin_lifecycle.py +241 -6
- {parallelazy-0.1.2 → parallelazy-0.1.3}/tests/test_plugin_logging.py +55 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/LICENSE +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/README.md +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/__init__.py +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/environment_manager.py +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/plugin_transport.py +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy/utils.py +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy.egg-info/SOURCES.txt +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy.egg-info/dependency_links.txt +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/parallelazy.egg-info/top_level.txt +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/setup.cfg +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/tests/test_env_cuda_ipc.py +0 -0
- {parallelazy-0.1.2 → parallelazy-0.1.3}/tests/test_plugin_monitoring.py +0 -0
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: parallelazy
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
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
|
|
7
7
|
Project-URL: Repository, https://github.com/cesare-montresor/parallelazy
|
|
8
8
|
Project-URL: Issues, https://github.com/cesare-montresor/parallelazy/issues
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
11
|
License-File: LICENSE
|
|
12
|
-
Requires-Dist: debugpy
|
|
13
12
|
Requires-Dist: torch
|
|
14
13
|
Requires-Dist: numpy
|
|
14
|
+
Provides-Extra: debug
|
|
15
|
+
Requires-Dist: debugpy; extra == "debug"
|
|
15
16
|
Dynamic: license-file
|
|
16
17
|
|
|
17
18
|
# parallelazy
|
|
@@ -64,6 +64,7 @@ class PluginDescriptor:
|
|
|
64
64
|
log_dir: Optional[str] = None
|
|
65
65
|
log_level: Optional[int] = None
|
|
66
66
|
display_logs: Optional[bool] = None
|
|
67
|
+
write_logs: Optional[bool] = None
|
|
67
68
|
|
|
68
69
|
def to_dict(self) -> Dict[str, Any]:
|
|
69
70
|
"""Convert descriptor to dictionary (JSON-serializable)."""
|
|
@@ -143,6 +144,7 @@ class Plugin:
|
|
|
143
144
|
log_dir: Optional[str] = None,
|
|
144
145
|
log_level: Optional[int] = None,
|
|
145
146
|
display_logs: Optional[bool] = None,
|
|
147
|
+
write_logs: Optional[bool] = None,
|
|
146
148
|
) -> PluginDescriptor:
|
|
147
149
|
all_options = cls.default_options().copy()
|
|
148
150
|
all_options.update(options or {})
|
|
@@ -160,6 +162,7 @@ class Plugin:
|
|
|
160
162
|
log_dir=log_dir,
|
|
161
163
|
log_level=log_level,
|
|
162
164
|
display_logs=display_logs,
|
|
165
|
+
write_logs=write_logs,
|
|
163
166
|
|
|
164
167
|
)
|
|
165
168
|
|
|
@@ -21,11 +21,23 @@ import logging
|
|
|
21
21
|
from concurrent.futures import Future
|
|
22
22
|
from torch import multiprocessing as mp
|
|
23
23
|
from dataclasses import dataclass, field, fields
|
|
24
|
+
from enum import IntEnum
|
|
24
25
|
from multiprocessing.connection import Connection
|
|
25
26
|
|
|
26
27
|
import threading
|
|
27
28
|
|
|
28
29
|
|
|
30
|
+
class PluginStartupPhase(IntEnum):
|
|
31
|
+
"""Startup milestones reported by a plugin worker process."""
|
|
32
|
+
|
|
33
|
+
NOT_STARTED = 0
|
|
34
|
+
PROCESS_STARTED = 1
|
|
35
|
+
WAITING_FOR_DEBUGGER = 2
|
|
36
|
+
INITIALIZING = 3
|
|
37
|
+
READY = 4
|
|
38
|
+
FAILED = 5
|
|
39
|
+
|
|
40
|
+
|
|
29
41
|
|
|
30
42
|
if TYPE_CHECKING:
|
|
31
43
|
from parallelazy.plugin_rpc import PluginRPC
|
|
@@ -344,11 +356,12 @@ class PluginStatus:
|
|
|
344
356
|
|
|
345
357
|
@dataclass
|
|
346
358
|
class ProcessStatus:
|
|
347
|
-
"""
|
|
359
|
+
"""Manager-side process state, including the worker's startup phase."""
|
|
348
360
|
plugin_id: str
|
|
349
361
|
process_alive: bool
|
|
350
362
|
process_pid: Optional[int]
|
|
351
363
|
worker_status: Optional[PluginStatus] = None
|
|
364
|
+
startup_phase: Optional[str] = None
|
|
352
365
|
|
|
353
366
|
|
|
354
367
|
|
|
@@ -455,6 +468,7 @@ class RequestEnvUnsubscribe(Request):
|
|
|
455
468
|
class RequestEnvUpdate(Request):
|
|
456
469
|
command: CommandType = field(default=CommandType.ENV_UPDATE, init=False)
|
|
457
470
|
name: str = None
|
|
471
|
+
value: Any = None
|
|
458
472
|
|
|
459
473
|
### Pub/Sub Requests
|
|
460
474
|
|
|
@@ -25,6 +25,7 @@ class PluginRuntimeSettings:
|
|
|
25
25
|
log_dir: str
|
|
26
26
|
log_level: int
|
|
27
27
|
display_logs: bool
|
|
28
|
+
write_logs: bool = True
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
def resolve_directory(path: str, base_dir: Optional[str] = None) -> str:
|
|
@@ -58,6 +59,7 @@ def default_runtime_settings() -> PluginRuntimeSettings:
|
|
|
58
59
|
log_dir=log_dir,
|
|
59
60
|
log_level=logging.INFO,
|
|
60
61
|
display_logs=True,
|
|
62
|
+
write_logs=True,
|
|
61
63
|
)
|
|
62
64
|
|
|
63
65
|
|
|
@@ -69,10 +71,17 @@ class _CapturedStreamConsoleFilter(logging.Filter):
|
|
|
69
71
|
class _TeeTextStream:
|
|
70
72
|
"""Mirror worker stream writes to the original stream and its log file."""
|
|
71
73
|
|
|
72
|
-
def __init__(
|
|
74
|
+
def __init__(
|
|
75
|
+
self,
|
|
76
|
+
stream: TextIO,
|
|
77
|
+
logger: logging.Logger,
|
|
78
|
+
label: str,
|
|
79
|
+
mirror_to_terminal: bool = True,
|
|
80
|
+
):
|
|
73
81
|
self._stream = stream
|
|
74
82
|
self._logger = logger
|
|
75
83
|
self._label = label
|
|
84
|
+
self._mirror_to_terminal = mirror_to_terminal
|
|
76
85
|
self._buffer = ""
|
|
77
86
|
self._lock = threading.RLock()
|
|
78
87
|
self._logging = threading.local()
|
|
@@ -110,9 +119,10 @@ class _TeeTextStream:
|
|
|
110
119
|
if not isinstance(text, str):
|
|
111
120
|
raise TypeError("write() argument must be str")
|
|
112
121
|
with self._lock:
|
|
113
|
-
written = self._stream.write(text)
|
|
122
|
+
written = self._stream.write(text) if self._mirror_to_terminal else len(text)
|
|
114
123
|
if "\r" in text or "\n" in text:
|
|
115
|
-
self.
|
|
124
|
+
if self._mirror_to_terminal:
|
|
125
|
+
self._stream.flush()
|
|
116
126
|
if not getattr(self._logging, "active", False):
|
|
117
127
|
self._capture_complete_lines(text)
|
|
118
128
|
return written
|
|
@@ -159,11 +169,21 @@ class _TeeTextStream:
|
|
|
159
169
|
class WorkerOutputCapture:
|
|
160
170
|
"""Restore worker streams after teeing their output into the worker log."""
|
|
161
171
|
|
|
162
|
-
def __init__(self, logger: logging.Logger):
|
|
172
|
+
def __init__(self, logger: logging.Logger, display_logs: bool = True):
|
|
163
173
|
self._original_stdout = sys.stdout
|
|
164
174
|
self._original_stderr = sys.stderr
|
|
165
|
-
self.stdout = _TeeTextStream(
|
|
166
|
-
|
|
175
|
+
self.stdout = _TeeTextStream(
|
|
176
|
+
self._original_stdout,
|
|
177
|
+
logger,
|
|
178
|
+
"stdout",
|
|
179
|
+
mirror_to_terminal=display_logs,
|
|
180
|
+
)
|
|
181
|
+
self.stderr = _TeeTextStream(
|
|
182
|
+
self._original_stderr,
|
|
183
|
+
logger,
|
|
184
|
+
"stderr",
|
|
185
|
+
mirror_to_terminal=display_logs,
|
|
186
|
+
)
|
|
167
187
|
sys.stdout = self.stdout
|
|
168
188
|
sys.stderr = self.stderr
|
|
169
189
|
|
|
@@ -178,9 +198,12 @@ class WorkerOutputCapture:
|
|
|
178
198
|
sys.stderr = self._original_stderr
|
|
179
199
|
|
|
180
200
|
|
|
181
|
-
def configure_worker_output(
|
|
182
|
-
|
|
183
|
-
|
|
201
|
+
def configure_worker_output(
|
|
202
|
+
logger: logging.Logger,
|
|
203
|
+
display_logs: bool = True,
|
|
204
|
+
) -> WorkerOutputCapture:
|
|
205
|
+
"""Mirror worker stdout and stderr to the plugin log and optionally the terminal."""
|
|
206
|
+
return WorkerOutputCapture(logger, display_logs=display_logs)
|
|
184
207
|
|
|
185
208
|
|
|
186
209
|
def _format_elapsed(seconds: float) -> str:
|
|
@@ -339,6 +362,7 @@ class LoggingSession:
|
|
|
339
362
|
log_level: int,
|
|
340
363
|
display_logs: bool,
|
|
341
364
|
replace_handlers: bool = False,
|
|
365
|
+
write_logs: bool = True,
|
|
342
366
|
):
|
|
343
367
|
if isinstance(log_level, bool) or not isinstance(log_level, int):
|
|
344
368
|
raise TypeError("log_level must be an integer logging level")
|
|
@@ -357,12 +381,13 @@ class LoggingSession:
|
|
|
357
381
|
logger.setLevel(log_level)
|
|
358
382
|
logger.propagate = False
|
|
359
383
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
384
|
+
if write_logs:
|
|
385
|
+
file_handler = _RecoveringFileHandler(log_file)
|
|
386
|
+
file_handler.setLevel(log_level)
|
|
387
|
+
file_handler.addFilter(self._context_filter)
|
|
388
|
+
file_handler.setFormatter(_make_formatter(self.file_format))
|
|
389
|
+
logger.addHandler(file_handler)
|
|
390
|
+
self._handlers.append(file_handler)
|
|
366
391
|
|
|
367
392
|
if display_logs:
|
|
368
393
|
console_handler = logging.StreamHandler(sys.stdout)
|
|
@@ -420,6 +445,7 @@ def configure_worker_logging(
|
|
|
420
445
|
log_level=settings.log_level,
|
|
421
446
|
display_logs=settings.display_logs,
|
|
422
447
|
replace_handlers=True,
|
|
448
|
+
write_logs=settings.write_logs,
|
|
423
449
|
)
|
|
424
450
|
|
|
425
451
|
|
|
@@ -428,6 +454,7 @@ def configure_manager_logging(
|
|
|
428
454
|
log_level: int,
|
|
429
455
|
display_logs: bool,
|
|
430
456
|
run_id: str,
|
|
457
|
+
write_logs: bool = True,
|
|
431
458
|
) -> LoggingSession:
|
|
432
459
|
manager_logger = logging.getLogger(f"parallelazy.manager.{run_id}")
|
|
433
460
|
return LoggingSession(
|
|
@@ -436,4 +463,5 @@ def configure_manager_logging(
|
|
|
436
463
|
plugin_id="manager",
|
|
437
464
|
log_level=log_level,
|
|
438
465
|
display_logs=display_logs,
|
|
466
|
+
write_logs=write_logs,
|
|
439
467
|
)
|