parallelazy 0.0.5__tar.gz → 0.0.7__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.0.5 → parallelazy-0.0.7}/PKG-INFO +9 -2
- {parallelazy-0.0.5 → parallelazy-0.0.7}/README.md +8 -1
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/plugin_manager.py +21 -11
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/plugin_worker.py +4 -4
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/utils.py +47 -15
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy.egg-info/PKG-INFO +9 -2
- {parallelazy-0.0.5 → parallelazy-0.0.7}/pyproject.toml +1 -1
- {parallelazy-0.0.5 → parallelazy-0.0.7}/LICENSE +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/__init__.py +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/environment_manager.py +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/plugin.py +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/plugin_data.py +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/plugin_rpc.py +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy/plugin_transport.py +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy.egg-info/SOURCES.txt +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy.egg-info/dependency_links.txt +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy.egg-info/requires.txt +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/parallelazy.egg-info/top_level.txt +0 -0
- {parallelazy-0.0.5 → parallelazy-0.0.7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: parallelazy
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
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
|
|
@@ -16,6 +16,8 @@ Dynamic: license-file
|
|
|
16
16
|
|
|
17
17
|
# parallelazy
|
|
18
18
|
|
|
19
|
+
[PyPi parallelazy](https://pypi.org/project/parallelazy/)
|
|
20
|
+
|
|
19
21
|
A lightweight Python plugin/worker framework with:
|
|
20
22
|
|
|
21
23
|
- isolated plugin processes started with `spawn`;
|
|
@@ -27,7 +29,12 @@ A lightweight Python plugin/worker framework with:
|
|
|
27
29
|
## Install
|
|
28
30
|
|
|
29
31
|
```bash
|
|
30
|
-
|
|
32
|
+
pip install parallelazy
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
*for development*
|
|
36
|
+
```bash
|
|
37
|
+
pip install -e .
|
|
31
38
|
```
|
|
32
39
|
|
|
33
40
|
## Debug in VSCode
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# parallelazy
|
|
2
2
|
|
|
3
|
+
[PyPi parallelazy](https://pypi.org/project/parallelazy/)
|
|
4
|
+
|
|
3
5
|
A lightweight Python plugin/worker framework with:
|
|
4
6
|
|
|
5
7
|
- isolated plugin processes started with `spawn`;
|
|
@@ -11,7 +13,12 @@ A lightweight Python plugin/worker framework with:
|
|
|
11
13
|
## Install
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
|
-
|
|
16
|
+
pip install parallelazy
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
*for development*
|
|
20
|
+
```bash
|
|
21
|
+
pip install -e .
|
|
15
22
|
```
|
|
16
23
|
|
|
17
24
|
## Debug in VSCode
|
|
@@ -13,10 +13,10 @@ import torch.multiprocessing as mp
|
|
|
13
13
|
import time
|
|
14
14
|
from typing import Any, Dict, List, Optional
|
|
15
15
|
|
|
16
|
-
from parallelazy.utils import process_start_spawn
|
|
16
|
+
from parallelazy.utils import is_debugging_enabled, is_debugpy_attached, process_start_spawn
|
|
17
17
|
from parallelazy.plugin import PluginDescriptor
|
|
18
18
|
from parallelazy.plugin_rpc import PluginRPC, RequestEnvGetAll, RequestEnvUnsubscribe, RequestTopicAnnounce
|
|
19
|
-
from parallelazy.plugin_worker import PluginWorker, Queue, RequestPluginCall, RequestTopicSubscribe, RequestTopicUnsubscribe
|
|
19
|
+
from parallelazy.plugin_worker import PluginWorker, Queue, RequestPluginCall, RequestTopicSubscribe, RequestTopicUnsubscribe, setup_worker_debugging_env
|
|
20
20
|
from parallelazy.plugin_data import CommandType, ProcessStatus, RequestEnvGet, RequestEnvSet, RequestEnvSubscribe, PluginStatus, Subscriber
|
|
21
21
|
from parallelazy.environment_manager import EnvironmentManager
|
|
22
22
|
|
|
@@ -52,8 +52,8 @@ class PluginManager:
|
|
|
52
52
|
def __init__(
|
|
53
53
|
self,
|
|
54
54
|
timeout_request: float = 5.0,
|
|
55
|
-
timeout_start: float =
|
|
56
|
-
|
|
55
|
+
timeout_start: float = 10.0,
|
|
56
|
+
timeout_start_debug: float = 30.0
|
|
57
57
|
):
|
|
58
58
|
"""
|
|
59
59
|
Initialize plugin manager.
|
|
@@ -61,7 +61,7 @@ class PluginManager:
|
|
|
61
61
|
Args:
|
|
62
62
|
timeout_request: Default timeout for sync requests (seconds)
|
|
63
63
|
timeout_start: Timeout for start command (seconds)
|
|
64
|
-
|
|
64
|
+
timeout_start_debug: Timeout for start command in debug mode (seconds)
|
|
65
65
|
"""
|
|
66
66
|
self._plugins: Dict[str, PluginInfo] = {} # plugin_id -> PluginInfo
|
|
67
67
|
self._plugins_lock = threading.Lock() # For thread-safe plugin management
|
|
@@ -73,8 +73,12 @@ class PluginManager:
|
|
|
73
73
|
self._env = EnvironmentManager()
|
|
74
74
|
|
|
75
75
|
self.timeout_request = timeout_request
|
|
76
|
-
self.
|
|
77
|
-
self.
|
|
76
|
+
self.worker_pydebug = is_debugpy_attached()
|
|
77
|
+
self.timeout_start = timeout_start if not self.worker_pydebug else timeout_start_debug
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if self.worker_pydebug:
|
|
81
|
+
setup_worker_debugging_env()
|
|
78
82
|
|
|
79
83
|
|
|
80
84
|
def load_plugins(self, descriptors: List[PluginDescriptor], parallel: bool = True) -> None:
|
|
@@ -136,7 +140,7 @@ class PluginManager:
|
|
|
136
140
|
# Spawn worker process
|
|
137
141
|
process = mp.Process(
|
|
138
142
|
target=PluginWorker.run,
|
|
139
|
-
args=(plugin_id, descriptor.to_dict(), options, worker_channel, initialized,
|
|
143
|
+
args=(plugin_id, descriptor.to_dict(), options, worker_channel, initialized),
|
|
140
144
|
name=f"plugin-{plugin_id}"
|
|
141
145
|
)
|
|
142
146
|
|
|
@@ -150,10 +154,16 @@ class PluginManager:
|
|
|
150
154
|
)
|
|
151
155
|
|
|
152
156
|
process.start()
|
|
153
|
-
is_ready =
|
|
157
|
+
is_ready = False
|
|
158
|
+
while process.is_alive():
|
|
159
|
+
is_ready = initialized.wait(timeout=self.timeout_start)
|
|
160
|
+
if is_ready: break
|
|
161
|
+
# If we get here, wait() timed out but the process is still alive
|
|
162
|
+
logger.info(f"Plugin {plugin_id} is still initializing (waiting...)")
|
|
163
|
+
|
|
164
|
+
# If the loop exited and is_ready is False, the process died before setting the event
|
|
154
165
|
if not is_ready:
|
|
155
|
-
logger.error(f"Plugin {plugin_id} failed to initialize
|
|
156
|
-
process.terminate()
|
|
166
|
+
logger.error(f"Plugin {plugin_id} failed to initialize (process terminated unexpectedly).")
|
|
157
167
|
return False
|
|
158
168
|
|
|
159
169
|
logger.info(f"Plugin {plugin_id} loaded")
|
|
@@ -18,7 +18,7 @@ import threading
|
|
|
18
18
|
import time
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
from parallelazy.utils import init_debugger, process_start_spawn
|
|
21
|
+
from parallelazy.utils import init_debugger, is_debugging_enabled, process_start_spawn, setup_worker_debugging_env
|
|
22
22
|
from parallelazy.plugin_data import Channel, CommandType, Queue,QueueDescriptor, PendingRequest, PluginStatus, RequestPluginErrors, RequestPluginStart, RequestPluginStatus, RequestPluginStop, RequestTopicList, Subscriber, Subscription
|
|
23
23
|
from parallelazy.plugin import Plugin, PluginDescriptor, PluginState
|
|
24
24
|
|
|
@@ -59,8 +59,7 @@ class PluginWorker:
|
|
|
59
59
|
descriptor_dict: Dict[str, Any],
|
|
60
60
|
options: Dict[str, Any],
|
|
61
61
|
queue_descriptor: QueueDescriptor,
|
|
62
|
-
initialized: Event
|
|
63
|
-
pydebug: bool = False
|
|
62
|
+
initialized: Event
|
|
64
63
|
) -> None:
|
|
65
64
|
"""
|
|
66
65
|
Entry point for plugin subprocess.
|
|
@@ -72,9 +71,10 @@ class PluginWorker:
|
|
|
72
71
|
queue_descriptor: Queue descriptor for communication
|
|
73
72
|
initialized: Event to signal initialization completion
|
|
74
73
|
"""
|
|
75
|
-
if
|
|
74
|
+
if is_debugging_enabled():
|
|
76
75
|
logger.setLevel(logging.DEBUG)
|
|
77
76
|
init_debugger(plugin_id)
|
|
77
|
+
|
|
78
78
|
|
|
79
79
|
worker = PluginWorker(
|
|
80
80
|
plugin_id,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
1
|
import os
|
|
3
2
|
import re
|
|
4
3
|
import socket
|
|
5
4
|
import logging
|
|
6
5
|
import torch.multiprocessing as mp
|
|
7
6
|
import warnings
|
|
7
|
+
import sys
|
|
8
8
|
|
|
9
9
|
logger = logging.getLogger(__name__)
|
|
10
10
|
|
|
@@ -22,19 +22,59 @@ def _notify_vscode_to_attach(port: int, process_name: str) -> None:
|
|
|
22
22
|
except Exception as e:
|
|
23
23
|
logger.warning(f"Failed to notify VS Code extension on port {ext_port_str}: {e}")
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
def get_debugpy():
|
|
26
|
+
if "debugpy" in sys.modules:
|
|
27
|
+
return sys.modules["debugpy"]
|
|
28
|
+
else:
|
|
29
|
+
try:
|
|
30
|
+
import debugpy
|
|
31
|
+
return debugpy
|
|
32
|
+
except ImportError:
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
def is_debugpy_attached() -> bool:
|
|
36
|
+
debugpy = get_debugpy()
|
|
37
|
+
if debugpy:
|
|
38
|
+
return debugpy.is_client_connected()
|
|
39
|
+
return False
|
|
40
|
+
|
|
41
|
+
def get_debugpy_path():
|
|
42
|
+
debugpy = get_debugpy()
|
|
43
|
+
if debugpy and hasattr(debugpy, "__file__"):
|
|
44
|
+
# Returns the 'libs' folder containing the IDE's debugpy
|
|
45
|
+
return os.path.dirname(os.path.dirname(debugpy.__file__))
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
def setup_worker_debugging_env() -> None:
|
|
49
|
+
"""Call this in the main process before spawning workers to export the debugger path."""
|
|
50
|
+
if is_debugpy_attached():
|
|
51
|
+
debug_path = get_debugpy_path()
|
|
52
|
+
if debug_path:
|
|
53
|
+
os.environ["_VSCODE_DEBUGPY_PATH"] = debug_path
|
|
54
|
+
|
|
55
|
+
def is_debugging_enabled() -> bool:
|
|
56
|
+
"""Check if debugging is enabled for the current process."""
|
|
57
|
+
return "_VSCODE_DEBUGPY_PATH" in os.environ
|
|
58
|
+
|
|
26
59
|
def init_debugger(process_name: str = 'worker', wait_for_client: bool = True) -> None:
|
|
60
|
+
"""Call this at the very beginning of your spawned worker's execution."""
|
|
61
|
+
# 1. Inject the IDE's debugpy path into sys.path before importing
|
|
62
|
+
debug_path = os.environ.get("_VSCODE_DEBUGPY_PATH")
|
|
63
|
+
if debug_path and debug_path not in sys.path:
|
|
64
|
+
sys.path.insert(0, debug_path)
|
|
65
|
+
|
|
66
|
+
# 2. Proceed with standard debugger initialization
|
|
27
67
|
try:
|
|
28
|
-
|
|
68
|
+
debugpy = get_debugpy()
|
|
69
|
+
if debugpy is None:
|
|
70
|
+
logger.warning("debugpy is not installed. Debugging will not be available.")
|
|
71
|
+
return
|
|
29
72
|
|
|
30
|
-
# Passing 0 tells the OS to assign a random free port.
|
|
31
|
-
# debugpy returns the actual port it bound to.
|
|
32
73
|
_, assigned_port = debugpy.listen(("localhost", 0))
|
|
33
74
|
|
|
34
75
|
logger.info(f"Debugger listening on port {assigned_port}")
|
|
35
76
|
print(f"Debugger listening on port {assigned_port} for {process_name} process", flush=True)
|
|
36
77
|
|
|
37
|
-
# Ping the extension silently bypassing stdout
|
|
38
78
|
_notify_vscode_to_attach(assigned_port, process_name)
|
|
39
79
|
|
|
40
80
|
if wait_for_client:
|
|
@@ -45,7 +85,6 @@ def init_debugger(process_name: str = 'worker', wait_for_client: bool = True) ->
|
|
|
45
85
|
except Exception as e:
|
|
46
86
|
logger.warning(f"Failed to initialize debugger: {e}")
|
|
47
87
|
|
|
48
|
-
|
|
49
88
|
def process_start_spawn(force=False):
|
|
50
89
|
current = mp.get_start_method(allow_none=True)
|
|
51
90
|
if current not in ('spawn', None):
|
|
@@ -53,19 +92,12 @@ def process_start_spawn(force=False):
|
|
|
53
92
|
elif current is None:
|
|
54
93
|
mp.set_start_method('spawn', force=force)
|
|
55
94
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
95
|
def camel_to_kebab(text):
|
|
60
|
-
# Find transitions from lowercase/number to uppercase
|
|
61
96
|
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1-\2', text)
|
|
62
|
-
# Find transitions from lowercase to uppercase/number
|
|
63
97
|
s2 = re.sub('([a-z0-9])([A-Z])', r'\1-\2', s1)
|
|
64
98
|
return s2.lower()
|
|
65
99
|
|
|
66
100
|
def camel_to_snake(text):
|
|
67
|
-
# Find transitions from lowercase/number to uppercase
|
|
68
101
|
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', text)
|
|
69
|
-
# Find transitions from lowercase to uppercase/number
|
|
70
102
|
s2 = re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1)
|
|
71
|
-
return s2.lower()
|
|
103
|
+
return s2.lower()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: parallelazy
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
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
|
|
@@ -16,6 +16,8 @@ Dynamic: license-file
|
|
|
16
16
|
|
|
17
17
|
# parallelazy
|
|
18
18
|
|
|
19
|
+
[PyPi parallelazy](https://pypi.org/project/parallelazy/)
|
|
20
|
+
|
|
19
21
|
A lightweight Python plugin/worker framework with:
|
|
20
22
|
|
|
21
23
|
- isolated plugin processes started with `spawn`;
|
|
@@ -27,7 +29,12 @@ A lightweight Python plugin/worker framework with:
|
|
|
27
29
|
## Install
|
|
28
30
|
|
|
29
31
|
```bash
|
|
30
|
-
|
|
32
|
+
pip install parallelazy
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
*for development*
|
|
36
|
+
```bash
|
|
37
|
+
pip install -e .
|
|
31
38
|
```
|
|
32
39
|
|
|
33
40
|
## Debug in VSCode
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "parallelazy"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.7"
|
|
8
8
|
description = "A lightweight multiprocess worker-plugin framework. Topic-based pub/sub, global enviroment, using process spawn and pipes, pytorch and CUDA ready."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.8"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|