isolate 0.14.0__py3-none-any.whl → 0.14.1__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 isolate might be problematic. Click here for more details.
- isolate/_isolate_version.py +2 -2
- isolate/server/server.py +67 -21
- {isolate-0.14.0.dist-info → isolate-0.14.1.dist-info}/METADATA +1 -1
- {isolate-0.14.0.dist-info → isolate-0.14.1.dist-info}/RECORD +8 -8
- {isolate-0.14.0.dist-info → isolate-0.14.1.dist-info}/LICENSE +0 -0
- {isolate-0.14.0.dist-info → isolate-0.14.1.dist-info}/WHEEL +0 -0
- {isolate-0.14.0.dist-info → isolate-0.14.1.dist-info}/entry_points.txt +0 -0
- {isolate-0.14.0.dist-info → isolate-0.14.1.dist-info}/top_level.txt +0 -0
isolate/_isolate_version.py
CHANGED
isolate/server/server.py
CHANGED
|
@@ -36,6 +36,7 @@ from isolate.server.health_server import HealthServicer
|
|
|
36
36
|
from isolate.server.interface import from_grpc, to_grpc
|
|
37
37
|
|
|
38
38
|
EMPTY_MESSAGE_INTERVAL = float(os.getenv("ISOLATE_EMPTY_MESSAGE_INTERVAL", "600"))
|
|
39
|
+
SKIP_EMPTY_LOGS = os.getenv("ISOLATE_SKIP_EMPTY_LOGS") == "1"
|
|
39
40
|
MAX_GRPC_WAIT_TIMEOUT = float(os.getenv("ISOLATE_MAX_GRPC_WAIT_TIMEOUT", "10.0"))
|
|
40
41
|
|
|
41
42
|
# Whether to inherit all the packages from the current environment or not.
|
|
@@ -464,7 +465,8 @@ class IsolateServicer(definitions.IsolateServicer):
|
|
|
464
465
|
return None
|
|
465
466
|
|
|
466
467
|
def cancel_tasks(self):
|
|
467
|
-
|
|
468
|
+
tasks_copy = self.background_tasks.copy()
|
|
469
|
+
for task in tasks_copy.values():
|
|
468
470
|
task.cancel()
|
|
469
471
|
|
|
470
472
|
|
|
@@ -484,8 +486,9 @@ class LogHandler:
|
|
|
484
486
|
task: RunTask
|
|
485
487
|
|
|
486
488
|
def handle(self, log: Log) -> None:
|
|
487
|
-
|
|
488
|
-
|
|
489
|
+
if not SKIP_EMPTY_LOGS or log.message.strip():
|
|
490
|
+
self.task.logger.log(log.level, log.message, source=log.source)
|
|
491
|
+
self._add_log_to_queue(log)
|
|
489
492
|
|
|
490
493
|
def _add_log_to_queue(self, log: Log) -> None:
|
|
491
494
|
grpc_log = cast(definitions.Log, to_grpc(log))
|
|
@@ -534,6 +537,16 @@ class SingleTaskInterceptor(ServerBoundInterceptor):
|
|
|
534
537
|
"""Sets server to terminate after the first Submit/Run task."""
|
|
535
538
|
|
|
536
539
|
_done: bool = False
|
|
540
|
+
_task_id: str | None = None
|
|
541
|
+
|
|
542
|
+
def __init__(self):
|
|
543
|
+
def terminate(request: Any, context: grpc.ServicerContext) -> Any:
|
|
544
|
+
context.abort(
|
|
545
|
+
grpc.StatusCode.RESOURCE_EXHAUSTED,
|
|
546
|
+
"Server has already served one Run/Submit task.",
|
|
547
|
+
)
|
|
548
|
+
|
|
549
|
+
self._terminator = grpc.unary_unary_rpc_method_handler(terminate)
|
|
537
550
|
|
|
538
551
|
def intercept_service(self, continuation, handler_call_details):
|
|
539
552
|
handler = continuation(handler_call_details)
|
|
@@ -542,29 +555,62 @@ class SingleTaskInterceptor(ServerBoundInterceptor):
|
|
|
542
555
|
is_run = handler_call_details.method == "/Isolate/Run"
|
|
543
556
|
is_new_task = is_submit or is_run
|
|
544
557
|
|
|
545
|
-
if is_new_task
|
|
546
|
-
raise grpc.RpcError(
|
|
547
|
-
grpc.StatusCode.UNAVAILABLE,
|
|
548
|
-
"Server has already served one Run/Submit task.",
|
|
549
|
-
)
|
|
550
|
-
elif is_new_task:
|
|
551
|
-
self._done = True
|
|
552
|
-
else:
|
|
558
|
+
if not is_new_task:
|
|
553
559
|
# Let other requests like List/Cancel/etc pass through
|
|
554
|
-
return
|
|
560
|
+
return handler
|
|
561
|
+
|
|
562
|
+
if self._done:
|
|
563
|
+
# Fail the request if the server has already served or is serving
|
|
564
|
+
# a Run/Submit task.
|
|
565
|
+
return self._terminator
|
|
566
|
+
|
|
567
|
+
self._done = True
|
|
555
568
|
|
|
556
569
|
def wrapper(method_impl):
|
|
557
570
|
@functools.wraps(method_impl)
|
|
558
|
-
def _wrapper(request, context):
|
|
559
|
-
def
|
|
560
|
-
if
|
|
561
|
-
|
|
562
|
-
|
|
571
|
+
def _wrapper(request: Any, context: grpc.ServicerContext) -> Any:
|
|
572
|
+
def termination() -> None:
|
|
573
|
+
if is_run:
|
|
574
|
+
print("Stopping server since run is finished")
|
|
575
|
+
# Stop the server after the Run task is finished
|
|
576
|
+
self.server.stop(grace=0.1)
|
|
577
|
+
|
|
578
|
+
elif is_submit:
|
|
579
|
+
# Wait until the task_id is assigned
|
|
580
|
+
while self._task_id is None:
|
|
563
581
|
time.sleep(0.1)
|
|
564
|
-
self.server.stop(grace=0.1)
|
|
565
582
|
|
|
566
|
-
|
|
567
|
-
|
|
583
|
+
# Get the task from the background tasks
|
|
584
|
+
task = self.servicer.background_tasks.get(self._task_id)
|
|
585
|
+
|
|
586
|
+
if task is not None:
|
|
587
|
+
# Wait until the task future is assigned
|
|
588
|
+
tries = 0
|
|
589
|
+
while task.future is None:
|
|
590
|
+
time.sleep(0.1)
|
|
591
|
+
tries += 1
|
|
592
|
+
if tries > 100:
|
|
593
|
+
raise RuntimeError(
|
|
594
|
+
"Task future was not assigned in time."
|
|
595
|
+
)
|
|
596
|
+
|
|
597
|
+
def _stop(*args):
|
|
598
|
+
# Small sleep to make sure the cancellation is processed
|
|
599
|
+
time.sleep(0.1)
|
|
600
|
+
print("Stopping server since the task is finished")
|
|
601
|
+
self.server.stop(grace=0.1)
|
|
602
|
+
|
|
603
|
+
# Add a callback which will stop the server
|
|
604
|
+
# after the task is finished
|
|
605
|
+
task.future.add_done_callback(_stop)
|
|
606
|
+
|
|
607
|
+
context.add_callback(termination)
|
|
608
|
+
res = method_impl(request, context)
|
|
609
|
+
|
|
610
|
+
if is_submit:
|
|
611
|
+
self._task_id = cast(definitions.SubmitResponse, res).task_id
|
|
612
|
+
|
|
613
|
+
return res
|
|
568
614
|
|
|
569
615
|
return _wrapper
|
|
570
616
|
|
|
@@ -598,7 +644,7 @@ def main(argv: list[str] | None = None) -> None:
|
|
|
598
644
|
server = grpc.server(
|
|
599
645
|
futures.ThreadPoolExecutor(max_workers=options.num_workers),
|
|
600
646
|
options=get_default_options(),
|
|
601
|
-
interceptors=interceptors,
|
|
647
|
+
interceptors=interceptors, # type: ignore
|
|
602
648
|
)
|
|
603
649
|
|
|
604
650
|
for interceptor in interceptors:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
isolate/__init__.py,sha256=uXOKnONs7sXgARNgElwr4_A1sKoA6ACHVEvs3IDiX1M,127
|
|
2
|
-
isolate/_isolate_version.py,sha256=
|
|
2
|
+
isolate/_isolate_version.py,sha256=2Ctgubb5b_lxFG2ixV07ZYKw5eto45wRlKsBIObkGsg,413
|
|
3
3
|
isolate/_version.py,sha256=05pXvy-yr5t3I1m9JMn42Ilzpg7fa8IB2J8a3G7t1cU,274
|
|
4
4
|
isolate/logger.py,sha256=d9mZyTOtplMZeQSNgRNiXhOPwJ0be2B1nGGaQx09C3g,1450
|
|
5
5
|
isolate/logs.py,sha256=R_AHUVYD18z_PhtK_mDWi9Gch79CxmwHY09hUDShtwg,2079
|
|
@@ -42,7 +42,7 @@ isolate/connections/ipc/agent.py,sha256=hGlL4x78FhRvMZ4DkVh3dk-EmWQqxHW4LIipgyOk
|
|
|
42
42
|
isolate/server/__init__.py,sha256=7R3GuWmxuqe0q28rVqETJN9OCrP_-Svjv9h0NR1GFL0,79
|
|
43
43
|
isolate/server/health_server.py,sha256=yN7F1Q28DdX8-Zk3gef7XcQEE25XwlHwzV5GBM75aQM,1249
|
|
44
44
|
isolate/server/interface.py,sha256=nGbjdxrN0p9m1LNdeds8NIoJOwPYW2NM6ktmbhfG4_s,687
|
|
45
|
-
isolate/server/server.py,sha256=
|
|
45
|
+
isolate/server/server.py,sha256=q0g0dL8hOosogGWpZMpXOOohTV55itp6f4K5yenvtBg,23233
|
|
46
46
|
isolate/server/definitions/__init__.py,sha256=f_Q3pdjMuZrjgNlbM60btFKiB1Vg8cnVyKEbp0RmU0A,572
|
|
47
47
|
isolate/server/definitions/server.proto,sha256=UihlFbYG8fbwm0IUfKDRH1vNkopzP3C-wplXXcAO1c8,1761
|
|
48
48
|
isolate/server/definitions/server_pb2.py,sha256=TYBJC_z_dNf2J6FgHukY9mDyc3WBt9EPQOVFd_ayQNc,4304
|
|
@@ -53,9 +53,9 @@ isolate/server/health/health.proto,sha256=wE2_QD0OQAblKkEBG7sALLXEOj1mOLKG-FbC4t
|
|
|
53
53
|
isolate/server/health/health_pb2.py,sha256=onOdP3M4Tpqhqs2PlGcyfoKe2VVKUEDx5ALeRcObb9A,1899
|
|
54
54
|
isolate/server/health/health_pb2.pyi,sha256=AK-DPCpJzoYhU6DydD856c0Ywx84x6k-Cs4m6HpNv5A,2459
|
|
55
55
|
isolate/server/health/health_pb2_grpc.py,sha256=XgsULrnRBmYIqvKr8eI7bqs6NIea5A0kkqdOOc2JHBY,5303
|
|
56
|
-
isolate-0.14.
|
|
57
|
-
isolate-0.14.
|
|
58
|
-
isolate-0.14.
|
|
59
|
-
isolate-0.14.
|
|
60
|
-
isolate-0.14.
|
|
61
|
-
isolate-0.14.
|
|
56
|
+
isolate-0.14.1.dist-info/LICENSE,sha256=427vuyirL5scgBLqA9UWcdnxKrtSGc0u_JfUupk6lAA,11359
|
|
57
|
+
isolate-0.14.1.dist-info/METADATA,sha256=_B69rNK-IJtBqsUjNwPXijhI_uLVcBTSLJ3jcbfl8Dk,3191
|
|
58
|
+
isolate-0.14.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
59
|
+
isolate-0.14.1.dist-info/entry_points.txt,sha256=s3prh2EERaVCbL8R45tfY5WFPZ1TsYOsz305YR7s-Pc,360
|
|
60
|
+
isolate-0.14.1.dist-info/top_level.txt,sha256=W9QJBHcq5WXRkbOXf25bvftzFsOZZN4n1DAatdroZrs,8
|
|
61
|
+
isolate-0.14.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|