engin 0.1.0b3__py3-none-any.whl → 0.1.0b5__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.
- engin/_engin.py +32 -19
- {engin-0.1.0b3.dist-info → engin-0.1.0b5.dist-info}/METADATA +1 -1
- {engin-0.1.0b3.dist-info → engin-0.1.0b5.dist-info}/RECORD +6 -6
- {engin-0.1.0b3.dist-info → engin-0.1.0b5.dist-info}/WHEEL +0 -0
- {engin-0.1.0b3.dist-info → engin-0.1.0b5.dist-info}/entry_points.txt +0 -0
- {engin-0.1.0b3.dist-info → engin-0.1.0b5.dist-info}/licenses/LICENSE +0 -0
engin/_engin.py
CHANGED
@@ -10,7 +10,7 @@ from itertools import chain
|
|
10
10
|
from types import FrameType
|
11
11
|
from typing import ClassVar
|
12
12
|
|
13
|
-
from anyio import create_task_group,
|
13
|
+
from anyio import create_task_group, open_signal_receiver
|
14
14
|
|
15
15
|
from engin._assembler import AssembledDependency, Assembler
|
16
16
|
from engin._dependency import Invoke, Provide, Supply
|
@@ -149,7 +149,7 @@ class Engin:
|
|
149
149
|
except Exception as err:
|
150
150
|
name = invocation.dependency.name
|
151
151
|
LOG.error(f"invocation '{name}' errored, exiting", exc_info=err)
|
152
|
-
|
152
|
+
raise
|
153
153
|
|
154
154
|
lifecycle = await self._assembler.build(Lifecycle)
|
155
155
|
|
@@ -177,10 +177,11 @@ class Engin:
|
|
177
177
|
try:
|
178
178
|
async with supervisor:
|
179
179
|
await self._stop_requested_event.wait()
|
180
|
-
|
181
|
-
|
180
|
+
await self._shutdown()
|
181
|
+
except BaseException:
|
182
|
+
await self._shutdown()
|
183
|
+
|
182
184
|
tg.cancel_scope.cancel()
|
183
|
-
await self._shutdown()
|
184
185
|
|
185
186
|
async def start(self) -> None:
|
186
187
|
"""
|
@@ -188,13 +189,25 @@ class Engin:
|
|
188
189
|
started to return so it is safe to use immediately after.
|
189
190
|
"""
|
190
191
|
self._async_context_run_task = asyncio.create_task(self.run())
|
192
|
+
wait_tasks = [
|
193
|
+
asyncio.create_task(self._start_complete_event.wait()),
|
194
|
+
asyncio.create_task(self._stop_complete_event.wait()),
|
195
|
+
]
|
191
196
|
await asyncio.wait(
|
192
197
|
[
|
193
|
-
|
194
|
-
|
198
|
+
self._async_context_run_task, # if a provider errors this will return first
|
199
|
+
*wait_tasks,
|
195
200
|
],
|
196
201
|
return_when=asyncio.FIRST_COMPLETED,
|
197
202
|
)
|
203
|
+
for task in wait_tasks:
|
204
|
+
task.cancel()
|
205
|
+
|
206
|
+
# raise the exception from the startup during run
|
207
|
+
if self._async_context_run_task.done():
|
208
|
+
startup_exception = self._async_context_run_task.exception()
|
209
|
+
if startup_exception is not None:
|
210
|
+
raise startup_exception
|
198
211
|
|
199
212
|
async def stop(self) -> None:
|
200
213
|
"""
|
@@ -205,7 +218,8 @@ class Engin:
|
|
205
218
|
started.
|
206
219
|
"""
|
207
220
|
self._stop_requested_event.set()
|
208
|
-
|
221
|
+
if self._state == _EnginState.RUNNING:
|
222
|
+
await self._stop_complete_event.wait()
|
209
223
|
|
210
224
|
def graph(self) -> list[Node]:
|
211
225
|
"""
|
@@ -224,24 +238,23 @@ class Engin:
|
|
224
238
|
return self._state == _EnginState.SHUTDOWN
|
225
239
|
|
226
240
|
async def _shutdown(self) -> None:
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
241
|
+
if self._state == _EnginState.RUNNING:
|
242
|
+
LOG.info("stopping engin")
|
243
|
+
await self._exit_stack.aclose()
|
244
|
+
self._stop_complete_event.set()
|
245
|
+
LOG.info("shutdown complete")
|
246
|
+
self._state = _EnginState.SHUTDOWN
|
232
247
|
|
233
248
|
|
234
249
|
async def _stop_engin_on_signal(stop_requested_event: Event) -> None:
|
235
250
|
"""
|
236
251
|
A task that waits for a stop signal (SIGINT/SIGTERM) and notifies the given event.
|
237
252
|
"""
|
238
|
-
# try to gracefully handle sigint/sigterm
|
239
253
|
if not _OS_IS_WINDOWS:
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
await stop_requested_event.wait()
|
254
|
+
with open_signal_receiver(signal.SIGINT, signal.SIGTERM) as recieved_signals:
|
255
|
+
async for signum in recieved_signals:
|
256
|
+
LOG.debug(f"received {signum.name} signal")
|
257
|
+
stop_requested_event.set()
|
245
258
|
else:
|
246
259
|
should_stop = False
|
247
260
|
|
@@ -2,7 +2,7 @@ engin/__init__.py,sha256=O0vS570kZFBq7Kwy4FgeJFIhfo4aIg5mv_Z_9vAQRio,577
|
|
2
2
|
engin/_assembler.py,sha256=MC14BRsgabGlq9weyv2VXylH4RE282uNTyNH5rN8Lqc,11359
|
3
3
|
engin/_block.py,sha256=IacP4PoJKRhSQCbQSdoyCtmu362a4vj6qoUQKyaJwzI,3062
|
4
4
|
engin/_dependency.py,sha256=xINk3sudxzsTmkUkNAKQwzBc0G0DfhpnrZli4z3ALBY,9459
|
5
|
-
engin/_engin.py,sha256
|
5
|
+
engin/_engin.py,sha256=36trLrhXfKXf1t237qTZb_B3cnE3YvlzHA1c2JQfzN8,9453
|
6
6
|
engin/_graph.py,sha256=y1g7Lm_Zy5GPEgRsggCKV5DDaDzcwUl8v3IZCK8jyGI,1631
|
7
7
|
engin/_introspect.py,sha256=VdREX6Lhhga5SnEP9G7mjHkgJR4mpqk_SMnmL2zTcqY,966
|
8
8
|
engin/_lifecycle.py,sha256=cSWe3euZkmpxmUPFvph2lsTtvuZbxttEfBL-RnOI7lo,5325
|
@@ -19,8 +19,8 @@ engin/_cli/_inspect.py,sha256=0jm25d4wcbXVNJkyaeECSKY-irsxd-EIYBH1GDW_Yjc,3163
|
|
19
19
|
engin/extensions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
20
|
engin/extensions/asgi.py,sha256=d5Z6gtMVWDZdAlvrTaMt987sKyiq__A0X4gJQ7IETmA,3247
|
21
21
|
engin/extensions/fastapi.py,sha256=7N6i-eZUEZRPo7kcvjS7kbRSY5QAPyKJXSeongSQ-OA,6371
|
22
|
-
engin-0.1.
|
23
|
-
engin-0.1.
|
24
|
-
engin-0.1.
|
25
|
-
engin-0.1.
|
26
|
-
engin-0.1.
|
22
|
+
engin-0.1.0b5.dist-info/METADATA,sha256=k-K33xQpJTOGemxOVp0K8MlwKHFArl7LpyBdNKrWeS4,3201
|
23
|
+
engin-0.1.0b5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
24
|
+
engin-0.1.0b5.dist-info/entry_points.txt,sha256=sW247zZUMxm0b5UKYvPuqQQljYDtU-j2zK3cu7gHwM0,41
|
25
|
+
engin-0.1.0b5.dist-info/licenses/LICENSE,sha256=XHh5LPUPKZWTBqBv2xxN2RU7D59nHoiJGb5RIt8f45w,1070
|
26
|
+
engin-0.1.0b5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|