wool 0.1rc9__py3-none-any.whl → 0.1rc11__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 +71 -50
- wool/_protobuf/__init__.py +12 -5
- wool/_protobuf/exception.py +3 -0
- wool/_protobuf/task.py +11 -0
- wool/_protobuf/task_pb2.py +42 -0
- wool/_protobuf/task_pb2.pyi +43 -0
- wool/_protobuf/{mempool/metadata_pb2_grpc.py → task_pb2_grpc.py} +2 -2
- wool/_protobuf/worker.py +24 -0
- wool/_protobuf/worker_pb2.py +47 -0
- wool/_protobuf/worker_pb2.pyi +39 -0
- wool/_protobuf/worker_pb2_grpc.py +141 -0
- wool/_resource_pool.py +376 -0
- wool/_typing.py +0 -10
- wool/_work.py +553 -0
- wool/_worker.py +843 -169
- wool/_worker_discovery.py +1223 -0
- wool/_worker_pool.py +337 -0
- wool/_worker_proxy.py +515 -0
- {wool-0.1rc9.dist-info → wool-0.1rc11.dist-info}/METADATA +7 -7
- wool-0.1rc11.dist-info/RECORD +22 -0
- wool-0.1rc11.dist-info/entry_points.txt +2 -0
- wool/_cli.py +0 -262
- wool/_event.py +0 -109
- wool/_future.py +0 -171
- wool/_logging.py +0 -44
- wool/_manager.py +0 -181
- wool/_mempool/__init__.py +0 -4
- wool/_mempool/_client.py +0 -167
- wool/_mempool/_mempool.py +0 -311
- wool/_mempool/_metadata.py +0 -35
- wool/_mempool/_service.py +0 -227
- wool/_pool.py +0 -524
- wool/_protobuf/mempool/metadata_pb2.py +0 -36
- wool/_protobuf/mempool/metadata_pb2.pyi +0 -17
- wool/_protobuf/mempool/service_pb2.py +0 -66
- wool/_protobuf/mempool/service_pb2.pyi +0 -108
- wool/_protobuf/mempool/service_pb2_grpc.py +0 -355
- wool/_queue.py +0 -32
- wool/_session.py +0 -429
- wool/_task.py +0 -366
- wool/_utils.py +0 -63
- wool-0.1rc9.dist-info/RECORD +0 -29
- wool-0.1rc9.dist-info/entry_points.txt +0 -2
- {wool-0.1rc9.dist-info → wool-0.1rc11.dist-info}/WHEEL +0 -0
wool/_mempool/_service.py
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import asyncio
|
|
4
|
-
from typing import AsyncGenerator
|
|
5
|
-
from typing import Final
|
|
6
|
-
from weakref import WeakSet
|
|
7
|
-
from weakref import WeakValueDictionary
|
|
8
|
-
|
|
9
|
-
import shortuuid
|
|
10
|
-
from grpc.aio import ServicerContext
|
|
11
|
-
|
|
12
|
-
from wool._mempool import MemoryPool
|
|
13
|
-
|
|
14
|
-
try:
|
|
15
|
-
from wool._protobuf.mempool import service_pb2 as pb
|
|
16
|
-
from wool._protobuf.mempool import service_pb2_grpc as rpc
|
|
17
|
-
except ImportError as e:
|
|
18
|
-
from wool._protobuf import ProtobufImportError
|
|
19
|
-
|
|
20
|
-
raise ProtobufImportError(e) from e
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class _Session:
|
|
24
|
-
id: Final[str]
|
|
25
|
-
queue: Final[asyncio.Queue[pb.SessionResponse]]
|
|
26
|
-
references: Final[set[_Reference]]
|
|
27
|
-
|
|
28
|
-
_sessions: Final[WeakValueDictionary[str, _Session]] = (
|
|
29
|
-
WeakValueDictionary()
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
@classmethod
|
|
33
|
-
def get(cls, id: str) -> _Session | None:
|
|
34
|
-
return cls._sessions.get(id)
|
|
35
|
-
|
|
36
|
-
def __init__(self):
|
|
37
|
-
self.id = shortuuid.uuid()
|
|
38
|
-
self.queue = asyncio.Queue()
|
|
39
|
-
self.references = set()
|
|
40
|
-
self._sessions[self.id] = self
|
|
41
|
-
|
|
42
|
-
def __eq__(self, other) -> bool:
|
|
43
|
-
if isinstance(other, _Session):
|
|
44
|
-
return self.id == other.id
|
|
45
|
-
return False
|
|
46
|
-
|
|
47
|
-
def __hash__(self) -> int:
|
|
48
|
-
return hash(self.id)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class _Reference:
|
|
52
|
-
id: Final[str]
|
|
53
|
-
sessions: Final[WeakSet[_Session]]
|
|
54
|
-
|
|
55
|
-
_mempool: Final[MemoryPool]
|
|
56
|
-
_references: Final[WeakValueDictionary[str, _Reference]] = (
|
|
57
|
-
WeakValueDictionary()
|
|
58
|
-
)
|
|
59
|
-
_to_delete: Final[set[str]] = set()
|
|
60
|
-
_initialized: bool = False
|
|
61
|
-
|
|
62
|
-
@classmethod
|
|
63
|
-
def get(cls, id: str) -> _Reference | None:
|
|
64
|
-
return cls._references.get(id)
|
|
65
|
-
|
|
66
|
-
@classmethod
|
|
67
|
-
def new(cls, id: str, *, mempool: MemoryPool) -> _Reference:
|
|
68
|
-
if id in cls._references:
|
|
69
|
-
raise ValueError(f"Reference {id} already exists")
|
|
70
|
-
return cls(id, mempool=mempool)
|
|
71
|
-
|
|
72
|
-
def __new__(cls, id: str, *, mempool: MemoryPool):
|
|
73
|
-
if id in cls._references:
|
|
74
|
-
if id in cls._to_delete:
|
|
75
|
-
cls._to_delete.remove(id)
|
|
76
|
-
return cls._references[id]
|
|
77
|
-
return super().__new__(cls)
|
|
78
|
-
|
|
79
|
-
def __init__(self, id: str, *, mempool: MemoryPool):
|
|
80
|
-
if not self._initialized:
|
|
81
|
-
self.id = id
|
|
82
|
-
self.sessions = WeakSet()
|
|
83
|
-
self._mempool = mempool
|
|
84
|
-
self._references[id] = self
|
|
85
|
-
self._initialized = True
|
|
86
|
-
|
|
87
|
-
def __eq__(self, other) -> bool:
|
|
88
|
-
if isinstance(other, _Reference):
|
|
89
|
-
return self.id == other.id
|
|
90
|
-
return False
|
|
91
|
-
|
|
92
|
-
def __hash__(self) -> int:
|
|
93
|
-
return hash(self.id)
|
|
94
|
-
|
|
95
|
-
def __del__(self):
|
|
96
|
-
self._to_delete.add(self.id)
|
|
97
|
-
|
|
98
|
-
async def _delete(id, to_delete, mempool):
|
|
99
|
-
if id in to_delete:
|
|
100
|
-
try:
|
|
101
|
-
to_delete.remove(id)
|
|
102
|
-
await mempool.delete(id)
|
|
103
|
-
except FileNotFoundError:
|
|
104
|
-
pass
|
|
105
|
-
|
|
106
|
-
try:
|
|
107
|
-
asyncio.get_running_loop().create_task(
|
|
108
|
-
_delete(self.id, self._to_delete, self._mempool)
|
|
109
|
-
)
|
|
110
|
-
except RuntimeError:
|
|
111
|
-
asyncio.new_event_loop().run_until_complete(
|
|
112
|
-
_delete(self.id, self._to_delete, self._mempool)
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
class MemoryPoolService(rpc.MemoryPoolServicer):
|
|
117
|
-
def __init__(self, mempool: MemoryPool | None = None):
|
|
118
|
-
self._mempool = mempool or MemoryPool()
|
|
119
|
-
self._shutdown = asyncio.Event()
|
|
120
|
-
|
|
121
|
-
async def session(
|
|
122
|
-
self, request: pb.SessionRequest, context: ServicerContext
|
|
123
|
-
) -> AsyncGenerator[pb.SessionResponse]:
|
|
124
|
-
session = _Session()
|
|
125
|
-
yield pb.SessionResponse(session=pb.Session(id=session.id))
|
|
126
|
-
while True:
|
|
127
|
-
yield await session.queue.get()
|
|
128
|
-
|
|
129
|
-
async def map(
|
|
130
|
-
self, request: pb.AcquireRequest, context: ServicerContext
|
|
131
|
-
) -> pb.AcquireResponse:
|
|
132
|
-
if not (session := _Session.get(request.session.id)):
|
|
133
|
-
raise ValueError(f"Session {request.session.id} not found")
|
|
134
|
-
await self._mempool.map(request.reference.id or None)
|
|
135
|
-
reference = _Reference(request.reference.id, mempool=self._mempool)
|
|
136
|
-
await self.acquire(
|
|
137
|
-
pb.AcquireRequest(
|
|
138
|
-
session=pb.Session(id=session.id),
|
|
139
|
-
reference=pb.Reference(id=reference.id),
|
|
140
|
-
),
|
|
141
|
-
context,
|
|
142
|
-
)
|
|
143
|
-
return pb.AcquireResponse()
|
|
144
|
-
|
|
145
|
-
async def put(
|
|
146
|
-
self, request: pb.PutRequest, context: ServicerContext
|
|
147
|
-
) -> pb.PutResponse:
|
|
148
|
-
if not (session := _Session.get(request.session.id)):
|
|
149
|
-
raise ValueError(f"Session {request.session.id} not found")
|
|
150
|
-
reference = _Reference(
|
|
151
|
-
id=await self._mempool.put(request.dump, mutable=request.mutable),
|
|
152
|
-
mempool=self._mempool,
|
|
153
|
-
)
|
|
154
|
-
await self.acquire(
|
|
155
|
-
pb.AcquireRequest(
|
|
156
|
-
session=pb.Session(id=session.id),
|
|
157
|
-
reference=pb.Reference(id=reference.id),
|
|
158
|
-
),
|
|
159
|
-
context,
|
|
160
|
-
)
|
|
161
|
-
return pb.PutResponse(reference=pb.Reference(id=reference.id))
|
|
162
|
-
|
|
163
|
-
async def get(
|
|
164
|
-
self, request: pb.GetRequest, context: ServicerContext
|
|
165
|
-
) -> pb.GetResponse:
|
|
166
|
-
if not (session := _Session.get(request.session.id)):
|
|
167
|
-
raise ValueError(f"Session {request.session.id} not found")
|
|
168
|
-
if _Reference.get(request.reference.id) is None:
|
|
169
|
-
await self.acquire(
|
|
170
|
-
pb.AcquireRequest(
|
|
171
|
-
session=pb.Session(id=session.id),
|
|
172
|
-
reference=pb.Reference(id=request.reference.id),
|
|
173
|
-
),
|
|
174
|
-
context,
|
|
175
|
-
)
|
|
176
|
-
dump = await self._mempool.get(request.reference.id)
|
|
177
|
-
return pb.GetResponse(dump=dump)
|
|
178
|
-
|
|
179
|
-
async def post(
|
|
180
|
-
self, request: pb.PostRequest, context: ServicerContext
|
|
181
|
-
) -> pb.PostResponse:
|
|
182
|
-
if not (session := _Session.get(request.session.id)):
|
|
183
|
-
raise ValueError(f"Session {request.session.id} not found")
|
|
184
|
-
if not (reference := _Reference.get(request.reference.id)):
|
|
185
|
-
raise ValueError(f"Reference {request.reference.id} not found")
|
|
186
|
-
if reference not in session.references:
|
|
187
|
-
await self.acquire(
|
|
188
|
-
pb.AcquireRequest(
|
|
189
|
-
session=pb.Session(id=session.id),
|
|
190
|
-
reference=pb.Reference(id=reference.id),
|
|
191
|
-
),
|
|
192
|
-
context,
|
|
193
|
-
)
|
|
194
|
-
updated = await self._mempool.post(request.reference.id, request.dump)
|
|
195
|
-
if updated:
|
|
196
|
-
for session in _Reference(
|
|
197
|
-
id=request.reference.id, mempool=self._mempool
|
|
198
|
-
).sessions:
|
|
199
|
-
if session.id is not request.session.id:
|
|
200
|
-
event = pb.Event(
|
|
201
|
-
reference=request.reference,
|
|
202
|
-
event_type="post",
|
|
203
|
-
)
|
|
204
|
-
await session.queue.put(pb.SessionResponse(event=event))
|
|
205
|
-
return pb.PostResponse(updated=updated)
|
|
206
|
-
|
|
207
|
-
async def acquire(
|
|
208
|
-
self, request: pb.AcquireRequest, context: ServicerContext
|
|
209
|
-
) -> pb.AcquireResponse:
|
|
210
|
-
if not (session := _Session.get(request.session.id)):
|
|
211
|
-
raise ValueError(f"Session {request.session.id} not found")
|
|
212
|
-
if not (reference := _Reference.get(request.reference.id)):
|
|
213
|
-
raise ValueError(f"Reference {request.reference.id} not found")
|
|
214
|
-
session.references.add(reference)
|
|
215
|
-
reference.sessions.add(session)
|
|
216
|
-
return pb.AcquireResponse()
|
|
217
|
-
|
|
218
|
-
async def release(
|
|
219
|
-
self, request: pb.ReleaseRequest, context: ServicerContext
|
|
220
|
-
) -> pb.ReleaseResponse:
|
|
221
|
-
if not (session := _Session.get(request.session.id)):
|
|
222
|
-
raise ValueError(f"Session {request.session.id} not found")
|
|
223
|
-
if not (reference := _Reference.get(request.reference.id)):
|
|
224
|
-
raise ValueError(f"Reference {request.reference.id} not found")
|
|
225
|
-
session.references.remove(reference)
|
|
226
|
-
reference.sessions.remove(session)
|
|
227
|
-
return pb.ReleaseResponse()
|