wool 0.1rc3__py3-none-any.whl → 0.1rc7__py3-none-any.whl
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.
Potentially problematic release.
This version of wool might be problematic. Click here for more details.
- wool/__init__.py +37 -27
- wool/_cli.py +93 -40
- wool/_event.py +109 -0
- wool/_future.py +82 -11
- wool/_logging.py +14 -1
- wool/_manager.py +36 -20
- wool/_mempool/__init__.py +3 -0
- wool/_mempool/_mempool.py +204 -0
- wool/_mempool/_metadata/__init__.py +41 -0
- wool/_pool.py +357 -149
- wool/_protobuf/.gitkeep +0 -0
- wool/_protobuf/_mempool/_metadata/_metadata_pb2.py +36 -0
- wool/_protobuf/_mempool/_metadata/_metadata_pb2.pyi +17 -0
- wool/_queue.py +2 -1
- wool/_session.py +429 -0
- wool/_task.py +174 -113
- wool/_typing.py +5 -1
- wool/_utils.py +10 -17
- wool/_worker.py +120 -73
- wool-0.1rc7.dist-info/METADATA +343 -0
- wool-0.1rc7.dist-info/RECORD +23 -0
- {wool-0.1rc3.dist-info → wool-0.1rc7.dist-info}/WHEEL +1 -2
- wool/_client.py +0 -206
- wool-0.1rc3.dist-info/METADATA +0 -137
- wool-0.1rc3.dist-info/RECORD +0 -17
- wool-0.1rc3.dist-info/top_level.txt +0 -1
- {wool-0.1rc3.dist-info → wool-0.1rc7.dist-info}/entry_points.txt +0 -0
wool/_worker.py
CHANGED
|
@@ -2,25 +2,80 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import logging
|
|
5
|
-
import
|
|
6
|
-
from
|
|
7
|
-
from multiprocessing import Process
|
|
5
|
+
from contextvars import ContextVar
|
|
6
|
+
from multiprocessing import Pipe
|
|
7
|
+
from multiprocessing import Process
|
|
8
|
+
from multiprocessing import current_process
|
|
8
9
|
from queue import Empty
|
|
9
|
-
from signal import Signals
|
|
10
|
-
from
|
|
10
|
+
from signal import Signals
|
|
11
|
+
from signal import signal
|
|
12
|
+
from threading import Event
|
|
13
|
+
from threading import Thread
|
|
11
14
|
from time import sleep
|
|
12
15
|
from typing import TYPE_CHECKING
|
|
13
16
|
|
|
14
17
|
import wool
|
|
15
|
-
from wool.
|
|
16
|
-
from wool._future import fulfill
|
|
18
|
+
from wool._event import TaskEvent
|
|
19
|
+
from wool._future import fulfill
|
|
20
|
+
from wool._future import poll
|
|
21
|
+
from wool._session import WorkerPoolSession
|
|
22
|
+
from wool._session import WorkerSession
|
|
17
23
|
|
|
18
24
|
if TYPE_CHECKING:
|
|
19
|
-
from wool._task import
|
|
25
|
+
from wool._task import Task
|
|
20
26
|
|
|
21
27
|
|
|
22
|
-
def
|
|
23
|
-
|
|
28
|
+
def _noop(*_):
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class Scheduler(Thread):
|
|
33
|
+
def __init__(
|
|
34
|
+
self,
|
|
35
|
+
address: tuple[str, int],
|
|
36
|
+
loop: asyncio.AbstractEventLoop,
|
|
37
|
+
stop_event: Event,
|
|
38
|
+
ready: Event,
|
|
39
|
+
timeout: float = 1,
|
|
40
|
+
*args,
|
|
41
|
+
**kwargs,
|
|
42
|
+
) -> None:
|
|
43
|
+
super().__init__(*args, name="Scheduler", **kwargs)
|
|
44
|
+
self._address: tuple[str, int] = address
|
|
45
|
+
self._loop: asyncio.AbstractEventLoop = loop
|
|
46
|
+
self._stop_event: Event = stop_event
|
|
47
|
+
self._timeout: float = timeout
|
|
48
|
+
self._worker_ready: Event = ready
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def session_context(self) -> ContextVar[WorkerPoolSession]:
|
|
52
|
+
return wool.__wool_session__
|
|
53
|
+
|
|
54
|
+
def run(self) -> None:
|
|
55
|
+
logging.debug("Thread started")
|
|
56
|
+
self._worker_ready.wait()
|
|
57
|
+
sleep(0.1)
|
|
58
|
+
with WorkerSession(address=self._address) as self.session:
|
|
59
|
+
self.session_context.set(
|
|
60
|
+
WorkerPoolSession(address=self._address).connect()
|
|
61
|
+
)
|
|
62
|
+
while not self._stop_event.is_set():
|
|
63
|
+
try:
|
|
64
|
+
task: Task = self.session.get(timeout=self._timeout)
|
|
65
|
+
except Empty:
|
|
66
|
+
continue
|
|
67
|
+
else:
|
|
68
|
+
self._schedule_task(task, self._loop)
|
|
69
|
+
logging.debug("Thread stopped")
|
|
70
|
+
|
|
71
|
+
def _schedule_task(
|
|
72
|
+
self, wool_task: Task, loop: asyncio.AbstractEventLoop
|
|
73
|
+
) -> None:
|
|
74
|
+
future = self.session.futures().setdefault(wool_task.id, wool.Future())
|
|
75
|
+
task = asyncio.run_coroutine_threadsafe(wool_task.run(), loop)
|
|
76
|
+
task.add_done_callback(fulfill(future))
|
|
77
|
+
asyncio.run_coroutine_threadsafe(poll(future, task), loop)
|
|
78
|
+
TaskEvent("task-scheduled", task=wool_task).emit()
|
|
24
79
|
|
|
25
80
|
|
|
26
81
|
class Worker(Process):
|
|
@@ -29,21 +84,31 @@ class Worker(Process):
|
|
|
29
84
|
address: tuple[str, int],
|
|
30
85
|
*args,
|
|
31
86
|
log_level: int = logging.INFO,
|
|
87
|
+
scheduler: type[Scheduler] = Scheduler,
|
|
32
88
|
**kwargs,
|
|
33
89
|
) -> None:
|
|
34
90
|
super().__init__(*args, **kwargs)
|
|
35
91
|
self._address: tuple[str, int] = address
|
|
36
92
|
self.log_level: int = log_level
|
|
93
|
+
self._scheduler_type = scheduler
|
|
94
|
+
self._get_stop, self._set_stop = Pipe(duplex=False)
|
|
95
|
+
self._get_ready, self._set_ready = Pipe(duplex=False)
|
|
37
96
|
|
|
38
97
|
@property
|
|
39
98
|
def loop(self) -> asyncio.AbstractEventLoop:
|
|
40
99
|
return asyncio.get_event_loop()
|
|
41
100
|
|
|
101
|
+
def start(self):
|
|
102
|
+
super().start()
|
|
103
|
+
self._get_ready.recv()
|
|
104
|
+
self._get_ready.close()
|
|
105
|
+
|
|
42
106
|
def run(self) -> None:
|
|
107
|
+
signal(Signals.SIGINT, _noop)
|
|
43
108
|
wool.__wool_worker__ = self
|
|
109
|
+
self._set_stop.close()
|
|
44
110
|
self._stop_event = Event()
|
|
45
|
-
|
|
46
|
-
signal(Signals.SIGTERM, partial(stop, self, False))
|
|
111
|
+
self._wait_event = Event()
|
|
47
112
|
|
|
48
113
|
if self.log_level:
|
|
49
114
|
wool.__log_level__ = self.log_level
|
|
@@ -53,102 +118,84 @@ class Worker(Process):
|
|
|
53
118
|
|
|
54
119
|
logging.debug("Thread started")
|
|
55
120
|
|
|
56
|
-
shutdown_sentinel = ShutdownSentinel(
|
|
57
|
-
stop_event=self._stop_event,
|
|
121
|
+
self.shutdown_sentinel = ShutdownSentinel(
|
|
122
|
+
stop_event=self._stop_event,
|
|
123
|
+
wait_event=self._wait_event,
|
|
124
|
+
loop=self.loop,
|
|
58
125
|
)
|
|
59
|
-
shutdown_sentinel.start()
|
|
126
|
+
self.shutdown_sentinel.start()
|
|
60
127
|
|
|
61
128
|
logging.debug("Spawning scheduler thread...")
|
|
62
|
-
scheduler =
|
|
129
|
+
self.scheduler = self._scheduler_type(
|
|
63
130
|
address=self._address,
|
|
64
131
|
loop=self.loop,
|
|
65
132
|
stop_event=self._stop_event,
|
|
133
|
+
ready=(_ready_event := Event()),
|
|
66
134
|
)
|
|
67
|
-
scheduler.start()
|
|
68
|
-
|
|
69
|
-
self.loop.run_forever
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
135
|
+
self.scheduler.start()
|
|
136
|
+
|
|
137
|
+
loop = Thread(target=self.loop.run_forever, name="EventLoop")
|
|
138
|
+
loop.start()
|
|
139
|
+
|
|
140
|
+
self._set_ready.send(True)
|
|
141
|
+
self._set_ready.close()
|
|
142
|
+
_ready_event.set()
|
|
143
|
+
self.stop(self._get_stop.recv())
|
|
144
|
+
self._get_stop.close()
|
|
145
|
+
self.scheduler.join()
|
|
146
|
+
loop.join()
|
|
147
|
+
self.shutdown_sentinel.join()
|
|
148
|
+
logging.info("Thread stopped")
|
|
149
|
+
|
|
150
|
+
def stop(self, wait: bool = True) -> None:
|
|
76
151
|
if self.pid == current_process().pid:
|
|
152
|
+
if wait and not self._wait_event.is_set():
|
|
153
|
+
self._wait_event.set()
|
|
77
154
|
if not self._stop_event.is_set():
|
|
78
|
-
|
|
79
|
-
for task in asyncio.all_tasks(self.loop):
|
|
80
|
-
task.cancel()
|
|
81
|
-
self._stop_event.set()
|
|
155
|
+
self._stop_event.set()
|
|
82
156
|
elif self.pid:
|
|
83
|
-
|
|
157
|
+
self._set_stop.send(wait)
|
|
84
158
|
|
|
85
159
|
|
|
86
160
|
class ShutdownSentinel(Thread):
|
|
87
161
|
def __init__(
|
|
88
162
|
self,
|
|
89
163
|
stop_event: Event,
|
|
164
|
+
wait_event: Event,
|
|
90
165
|
loop: asyncio.AbstractEventLoop,
|
|
91
166
|
*args,
|
|
92
167
|
**kwargs,
|
|
93
168
|
) -> None:
|
|
94
169
|
super().__init__(*args, name="ShutdownSentinel", **kwargs)
|
|
95
170
|
self._stop_event: Event = stop_event
|
|
171
|
+
self._wait_event: Event = wait_event
|
|
96
172
|
self._loop: asyncio.AbstractEventLoop = loop
|
|
97
173
|
|
|
98
174
|
def run(self) -> None:
|
|
99
175
|
logging.debug("Thread started")
|
|
100
176
|
self._stop_event.wait()
|
|
177
|
+
logging.debug("Shutdown signal received")
|
|
178
|
+
if not self._wait_event.is_set():
|
|
179
|
+
logging.warning("Cancelling tasks...")
|
|
180
|
+
asyncio.run_coroutine_threadsafe(self._cancel_tasks(), self._loop)
|
|
101
181
|
if tasks := asyncio.all_tasks(self._loop):
|
|
182
|
+
logging.info("Gathering tasks...")
|
|
102
183
|
future = asyncio.run_coroutine_threadsafe(
|
|
103
|
-
self.
|
|
184
|
+
self._gather(*tasks), self._loop
|
|
104
185
|
)
|
|
105
186
|
while not future.done():
|
|
106
187
|
sleep(0.1)
|
|
107
188
|
self._loop.call_soon_threadsafe(self._loop.stop)
|
|
108
189
|
logging.debug("Thread stopped")
|
|
109
190
|
|
|
110
|
-
async def
|
|
191
|
+
async def _gather(self, *tasks: asyncio.Task) -> list:
|
|
111
192
|
return await asyncio.gather(*tasks, return_exceptions=True)
|
|
112
193
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
self,
|
|
117
|
-
address: tuple[str, int],
|
|
118
|
-
loop: asyncio.AbstractEventLoop,
|
|
119
|
-
stop_event: Event,
|
|
120
|
-
timeout: float = 1,
|
|
121
|
-
*args,
|
|
122
|
-
**kwargs,
|
|
123
|
-
) -> None:
|
|
124
|
-
super().__init__(*args, name="Scheduler", **kwargs)
|
|
125
|
-
self._address: tuple[str, int] = address
|
|
126
|
-
self._loop: asyncio.AbstractEventLoop = loop
|
|
127
|
-
self._stop_event: Event = stop_event
|
|
128
|
-
self._timeout: float = timeout
|
|
129
|
-
|
|
130
|
-
def run(self) -> None:
|
|
131
|
-
logging.debug("Thread started")
|
|
132
|
-
self.client = WorkerClient(address=self._address)
|
|
133
|
-
self.client.connect()
|
|
134
|
-
wool.__wool_client__.set(WoolClient(address=self._address))
|
|
135
|
-
queue = self.client.queue()
|
|
136
|
-
while not self._stop_event.is_set():
|
|
137
|
-
try:
|
|
138
|
-
task: WoolTask = queue.get(timeout=self._timeout)
|
|
139
|
-
except Empty:
|
|
194
|
+
async def _cancel_tasks(self):
|
|
195
|
+
for task in asyncio.all_tasks(self._loop):
|
|
196
|
+
if task == asyncio.current_task(self._loop):
|
|
140
197
|
continue
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def _schedule_task(
|
|
147
|
-
self, wool_task: WoolTask, loop: asyncio.AbstractEventLoop
|
|
148
|
-
) -> None:
|
|
149
|
-
future = self.client.futures().setdefault(
|
|
150
|
-
wool_task.id, wool.WoolFuture()
|
|
151
|
-
)
|
|
152
|
-
task = asyncio.run_coroutine_threadsafe(wool_task.run(), loop)
|
|
153
|
-
task.add_done_callback(fulfill(future))
|
|
154
|
-
asyncio.run_coroutine_threadsafe(poll(future, task), loop)
|
|
198
|
+
if task.get_coro():
|
|
199
|
+
if task.cancel():
|
|
200
|
+
logging.debug(f"Cancelled task {task.get_coro()}")
|
|
201
|
+
await asyncio.sleep(0)
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wool
|
|
3
|
+
Version: 0.1rc7
|
|
4
|
+
Summary: A Python framework for distributed multiprocessing.
|
|
5
|
+
Author-email: Conrad Bzura <conrad@wool.io>
|
|
6
|
+
Maintainer-email: maintainers@wool.io
|
|
7
|
+
License: Apache License
|
|
8
|
+
Version 2.0, January 2004
|
|
9
|
+
http://www.apache.org/licenses/
|
|
10
|
+
|
|
11
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
12
|
+
|
|
13
|
+
1. Definitions.
|
|
14
|
+
|
|
15
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
16
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
17
|
+
|
|
18
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
19
|
+
the copyright owner that is granting the License.
|
|
20
|
+
|
|
21
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
22
|
+
other entities that control, are controlled by, or are under common
|
|
23
|
+
control with that entity. For the purposes of this definition,
|
|
24
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
25
|
+
direction or management of such entity, whether by contract or
|
|
26
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
27
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
28
|
+
|
|
29
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
30
|
+
exercising permissions granted by this License.
|
|
31
|
+
|
|
32
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
33
|
+
including but not limited to software source code, documentation
|
|
34
|
+
source, and configuration files.
|
|
35
|
+
|
|
36
|
+
"Object" form shall mean any form resulting from mechanical
|
|
37
|
+
transformation or translation of a Source form, including but
|
|
38
|
+
not limited to compiled object code, generated documentation,
|
|
39
|
+
and conversions to other media types.
|
|
40
|
+
|
|
41
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
42
|
+
Object form, made available under the License, as indicated by a
|
|
43
|
+
copyright notice that is included in or attached to the work
|
|
44
|
+
(an example is provided in the Appendix below).
|
|
45
|
+
|
|
46
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
47
|
+
form, that is based on (or derived from) the Work and for which the
|
|
48
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
49
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
50
|
+
of this License, Derivative Works shall not include works that remain
|
|
51
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
52
|
+
the Work and Derivative Works thereof.
|
|
53
|
+
|
|
54
|
+
"Contribution" shall mean any work of authorship, including
|
|
55
|
+
the original version of the Work and any modifications or additions
|
|
56
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
57
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
58
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
59
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
60
|
+
means any form of electronic, verbal, or written communication sent
|
|
61
|
+
to the Licensor or its representatives, including but not limited to
|
|
62
|
+
communication on electronic mailing lists, source code control systems,
|
|
63
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
64
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
65
|
+
excluding communication that is conspicuously marked or otherwise
|
|
66
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
67
|
+
|
|
68
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
69
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
70
|
+
subsequently incorporated within the Work.
|
|
71
|
+
|
|
72
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
73
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
74
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
75
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
76
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
77
|
+
Work and such Derivative Works in Source or Object form.
|
|
78
|
+
|
|
79
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
80
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
81
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
82
|
+
(except as stated in this section) patent license to make, have made,
|
|
83
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
84
|
+
where such license applies only to those patent claims licensable
|
|
85
|
+
by such Contributor that are necessarily infringed by their
|
|
86
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
87
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
88
|
+
institute patent litigation against any entity (including a
|
|
89
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
90
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
91
|
+
or contributory patent infringement, then any patent licenses
|
|
92
|
+
granted to You under this License for that Work shall terminate
|
|
93
|
+
as of the date such litigation is filed.
|
|
94
|
+
|
|
95
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
96
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
97
|
+
modifications, and in Source or Object form, provided that You
|
|
98
|
+
meet the following conditions:
|
|
99
|
+
|
|
100
|
+
(a) You must give any other recipients of the Work or
|
|
101
|
+
Derivative Works a copy of this License; and
|
|
102
|
+
|
|
103
|
+
(b) You must cause any modified files to carry prominent notices
|
|
104
|
+
stating that You changed the files; and
|
|
105
|
+
|
|
106
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
107
|
+
that You distribute, all copyright, patent, trademark, and
|
|
108
|
+
attribution notices from the Source form of the Work,
|
|
109
|
+
excluding those notices that do not pertain to any part of
|
|
110
|
+
the Derivative Works; and
|
|
111
|
+
|
|
112
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
113
|
+
distribution, then any Derivative Works that You distribute must
|
|
114
|
+
include a readable copy of the attribution notices contained
|
|
115
|
+
within such NOTICE file, excluding those notices that do not
|
|
116
|
+
pertain to any part of the Derivative Works, in at least one
|
|
117
|
+
of the following places: within a NOTICE text file distributed
|
|
118
|
+
as part of the Derivative Works; within the Source form or
|
|
119
|
+
documentation, if provided along with the Derivative Works; or,
|
|
120
|
+
within a display generated by the Derivative Works, if and
|
|
121
|
+
wherever such third-party notices normally appear. The contents
|
|
122
|
+
of the NOTICE file are for informational purposes only and
|
|
123
|
+
do not modify the License. You may add Your own attribution
|
|
124
|
+
notices within Derivative Works that You distribute, alongside
|
|
125
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
126
|
+
that such additional attribution notices cannot be construed
|
|
127
|
+
as modifying the License.
|
|
128
|
+
|
|
129
|
+
You may add Your own copyright statement to Your modifications and
|
|
130
|
+
may provide additional or different license terms and conditions
|
|
131
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
132
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
133
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
134
|
+
the conditions stated in this License.
|
|
135
|
+
|
|
136
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
137
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
138
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
139
|
+
this License, without any additional terms or conditions.
|
|
140
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
141
|
+
the terms of any separate license agreement you may have executed
|
|
142
|
+
with Licensor regarding such Contributions.
|
|
143
|
+
|
|
144
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
145
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
146
|
+
except as required for reasonable and customary use in describing the
|
|
147
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
148
|
+
|
|
149
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
150
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
151
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
152
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
153
|
+
implied, including, without limitation, any warranties or conditions
|
|
154
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
155
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
156
|
+
appropriateness of using or redistributing the Work and assume any
|
|
157
|
+
risks associated with Your exercise of permissions under this License.
|
|
158
|
+
|
|
159
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
160
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
161
|
+
unless required by applicable law (such as deliberate and grossly
|
|
162
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
163
|
+
liable to You for damages, including any direct, indirect, special,
|
|
164
|
+
incidental, or consequential damages of any character arising as a
|
|
165
|
+
result of this License or out of the use or inability to use the
|
|
166
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
167
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
168
|
+
other commercial damages or losses), even if such Contributor
|
|
169
|
+
has been advised of the possibility of such damages.
|
|
170
|
+
|
|
171
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
172
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
173
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
174
|
+
or other liability obligations and/or rights consistent with this
|
|
175
|
+
License. However, in accepting such obligations, You may act only
|
|
176
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
177
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
178
|
+
defend, and hold each Contributor harmless for any liability
|
|
179
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
180
|
+
of your accepting any such warranty or additional liability.
|
|
181
|
+
|
|
182
|
+
END OF TERMS AND CONDITIONS
|
|
183
|
+
|
|
184
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
185
|
+
|
|
186
|
+
To apply the Apache License to your work, attach the following
|
|
187
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
188
|
+
replaced with your own identifying information. (Don't include
|
|
189
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
190
|
+
comment syntax for the file format. We also recommend that a
|
|
191
|
+
file or class name and description of purpose be included on the
|
|
192
|
+
same "printed page" as the copyright notice for easier
|
|
193
|
+
identification within third-party archives.
|
|
194
|
+
|
|
195
|
+
Copyright 2025 Wool Labs LLC
|
|
196
|
+
|
|
197
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
198
|
+
you may not use this file except in compliance with the License.
|
|
199
|
+
You may obtain a copy of the License at
|
|
200
|
+
|
|
201
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
202
|
+
|
|
203
|
+
Unless required by applicable law or agreed to in writing, software
|
|
204
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
205
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
206
|
+
See the License for the specific language governing permissions and
|
|
207
|
+
limitations under the License.
|
|
208
|
+
Classifier: Intended Audience :: Developers
|
|
209
|
+
Requires-Python: >=3.10
|
|
210
|
+
Requires-Dist: annotated-types
|
|
211
|
+
Requires-Dist: click
|
|
212
|
+
Requires-Dist: debugpy
|
|
213
|
+
Requires-Dist: protobuf
|
|
214
|
+
Requires-Dist: shortuuid
|
|
215
|
+
Requires-Dist: tblib
|
|
216
|
+
Provides-Extra: dev
|
|
217
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
218
|
+
Requires-Dist: pytest-asyncio; extra == 'dev'
|
|
219
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
220
|
+
Provides-Extra: locking
|
|
221
|
+
Requires-Dist: wool-locking==0.1rc7; extra == 'locking'
|
|
222
|
+
Description-Content-Type: text/markdown
|
|
223
|
+
|
|
224
|
+
# Wool
|
|
225
|
+
|
|
226
|
+
Wool is a native Python package for transparently executing tasks in a horizontally scalable, distributed network of agnostic worker processes. Any picklable async function or method can be converted into a task with a simple decorator and a client connection.
|
|
227
|
+
|
|
228
|
+
## Installation
|
|
229
|
+
|
|
230
|
+
### Using pip
|
|
231
|
+
|
|
232
|
+
To install the package using pip, run the following command:
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
[uv] pip install --pre wool
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Cloning from GitHub
|
|
239
|
+
|
|
240
|
+
To install the package by cloning from GitHub, run the following commands:
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
git clone https://github.com/wool-labs/wool.git
|
|
244
|
+
cd wool
|
|
245
|
+
[uv] pip install ./wool
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Usage
|
|
249
|
+
|
|
250
|
+
### CLI Commands
|
|
251
|
+
|
|
252
|
+
Wool provides a command-line interface (CLI) for managing the worker pool.
|
|
253
|
+
|
|
254
|
+
To list the available commands:
|
|
255
|
+
|
|
256
|
+
```sh
|
|
257
|
+
wool --help
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### Start the Worker Pool
|
|
261
|
+
|
|
262
|
+
To start the worker pool, use the `up` command:
|
|
263
|
+
|
|
264
|
+
```sh
|
|
265
|
+
wool pool up --host <host> --port <port> --authkey <authkey> --breadth <breadth> --module <module>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
- `--host`: The host address (default: `localhost`).
|
|
269
|
+
- `--port`: The port number (default: `0`).
|
|
270
|
+
- `--authkey`: The authentication key (default: `b""`).
|
|
271
|
+
- `--breadth`: The number of worker processes (default: number of CPU cores).
|
|
272
|
+
- `--module`: Python module containing Wool task definitions to be executed by this pool (optional, can be specified multiple times).
|
|
273
|
+
|
|
274
|
+
#### Stop the Worker Pool
|
|
275
|
+
|
|
276
|
+
To stop the worker pool, use the `down` command:
|
|
277
|
+
|
|
278
|
+
```sh
|
|
279
|
+
wool pool down --host <host> --port <port> --authkey <authkey> --wait
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
- `--host`: The host address (default: `localhost`).
|
|
283
|
+
- `--port`: The port number (required).
|
|
284
|
+
- `--authkey`: The authentication key (default: `b""`).
|
|
285
|
+
- `--wait`: Wait for in-flight tasks to complete before shutting down.
|
|
286
|
+
|
|
287
|
+
#### Ping the Worker Pool
|
|
288
|
+
|
|
289
|
+
To ping the worker pool, use the `ping` command:
|
|
290
|
+
|
|
291
|
+
```sh
|
|
292
|
+
wool ping --host <host> --port <port> --authkey <authkey>
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
- `--host`: The host address (default: `localhost`).
|
|
296
|
+
- `--port`: The port number (required).
|
|
297
|
+
- `--authkey`: The authentication key (default: `b""`).
|
|
298
|
+
|
|
299
|
+
### Sample Python Application
|
|
300
|
+
|
|
301
|
+
Below is an example of how to create a Wool client connection, decorate an async function using the `task` decorator, and execute the function remotely:
|
|
302
|
+
|
|
303
|
+
Module defining remote tasks:
|
|
304
|
+
`tasks.py`
|
|
305
|
+
```python
|
|
306
|
+
import asyncio, wool
|
|
307
|
+
|
|
308
|
+
# Decorate an async function using the `task` decorator
|
|
309
|
+
@wool.task
|
|
310
|
+
async def sample_task(x, y):
|
|
311
|
+
await asyncio.sleep(1)
|
|
312
|
+
return x + y
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Module executing remote workflow:
|
|
316
|
+
`main.py`
|
|
317
|
+
```python
|
|
318
|
+
import asyncio, wool
|
|
319
|
+
from tasks import sample_task
|
|
320
|
+
|
|
321
|
+
# Execute the decorated function in an external worker pool
|
|
322
|
+
async def main():
|
|
323
|
+
with wool.PoolSession(port=5050, authkey=b"deadbeef"):
|
|
324
|
+
result = await sample_task(1, 2)
|
|
325
|
+
print(f"Result: {result}")
|
|
326
|
+
|
|
327
|
+
asyncio.new_event_loop().run_until_complete(main())
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
To run the demo, first start a worker pool specifying the module defining the tasks to be executed:
|
|
331
|
+
```bash
|
|
332
|
+
wool pool up --port 5050 --authkey deadbeef --breadth 1 --module tasks
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Next, in a separate terminal, execute the application defined in `main.py` and, finally, stop the worker pool:
|
|
336
|
+
```bash
|
|
337
|
+
python main.py
|
|
338
|
+
wool pool down --port 5050 --authkey deadbeef
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## License
|
|
342
|
+
|
|
343
|
+
This project is licensed under the Apache License Version 2.0.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
wool/__init__.py,sha256=I5_ROaxPM764bhVbirFqLN62TyFrwS8Z47IR7wN4e1k,1900
|
|
2
|
+
wool/_cli.py,sha256=zLJqrT6nyLWNR83z40WsF279zJlE13UdDAhLuwoo50s,6565
|
|
3
|
+
wool/_event.py,sha256=3fixaB2FN9Uetgkpwnw9MikohaRq2NwdnWEMFwPz3A4,2965
|
|
4
|
+
wool/_future.py,sha256=Wn-wOuxfN9_R1-7wTzZGPUSl-IRYy5OM8ml68Ah6VuQ,4792
|
|
5
|
+
wool/_logging.py,sha256=r4iLicEjuYo1P7GMs1OB0GkHo9NKAFocvoR3RAnvrRA,1262
|
|
6
|
+
wool/_manager.py,sha256=QjYH73OPyTBeiOhJhbKJS9cPhuAIN2EOb14bUxZWI4o,4222
|
|
7
|
+
wool/_pool.py,sha256=vdQAjA0J7X5aa5VldjqgMxTMqp2t_K9268obZDKeT3M,15598
|
|
8
|
+
wool/_queue.py,sha256=qiTIezBe7sYvNszSRGDilumE49wlO3VWyMA74PgofeU,978
|
|
9
|
+
wool/_session.py,sha256=Dv2hYLvfv_zCoiptt27o6GqZkgHZoNvak6pAIz7znaA,11842
|
|
10
|
+
wool/_task.py,sha256=FRWyLb2geFGJmUtdn7RO_xjJSrUU_1TMDA9Mc9tBB8Y,10954
|
|
11
|
+
wool/_typing.py,sha256=FmTNTqJtist1rlaVAVSyg12AW9RwqcbvqC4M1u88iSU,397
|
|
12
|
+
wool/_utils.py,sha256=dHhgCp51oGjvKYCOYBjgWj6C03k2ZvclalrCZ4hH3sU,1527
|
|
13
|
+
wool/_worker.py,sha256=bEjPOHciLjLc-R456sX6EoImq9CTEGaLiZOOZP1BJYI,6434
|
|
14
|
+
wool/_mempool/__init__.py,sha256=gciN0LCV0G4cbJrL2rxmtu7e8lFJk8wCWqQQWpw5mOs,72
|
|
15
|
+
wool/_mempool/_mempool.py,sha256=vG_mhrM2RtDHHfULDyK7Qti_qjbWuW-IjjbtFflkmXs,6618
|
|
16
|
+
wool/_mempool/_metadata/__init__.py,sha256=5tojyNteoJto5tMhxpPj74Iiufa9I74Mbylcge5lTGQ,930
|
|
17
|
+
wool/_protobuf/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
wool/_protobuf/_mempool/_metadata/_metadata_pb2.py,sha256=PDMp6NwAod_r0vp0guO5aDrb8P_8ClT1KiNudqLb-rQ,1489
|
|
19
|
+
wool/_protobuf/_mempool/_metadata/_metadata_pb2.pyi,sha256=Tp6EcQF0ScsT-lNG9844yfwTkDkQwtLkDn6u2gMbjfE,653
|
|
20
|
+
wool-0.1rc7.dist-info/METADATA,sha256=3_7sv9XzIwJ9UQSJ8CqeZdVOnTANvTWw99xpO1JDHwc,16825
|
|
21
|
+
wool-0.1rc7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
22
|
+
wool-0.1rc7.dist-info/entry_points.txt,sha256=ybzb5TYXou-2cKC8HP5p0X8bw6Iyv7UMasqml6zlO1k,39
|
|
23
|
+
wool-0.1rc7.dist-info/RECORD,,
|