blaxel 0.2.1rc72__py3-none-any.whl → 0.2.1rc73__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.
- blaxel/core/sandbox/process.py +60 -5
- {blaxel-0.2.1rc72.dist-info → blaxel-0.2.1rc73.dist-info}/METADATA +1 -1
- {blaxel-0.2.1rc72.dist-info → blaxel-0.2.1rc73.dist-info}/RECORD +5 -5
- {blaxel-0.2.1rc72.dist-info → blaxel-0.2.1rc73.dist-info}/WHEEL +0 -0
- {blaxel-0.2.1rc72.dist-info → blaxel-0.2.1rc73.dist-info}/licenses/LICENSE +0 -0
blaxel/core/sandbox/process.py
CHANGED
@@ -10,6 +10,21 @@ from .client.models.process_request import ProcessRequest
|
|
10
10
|
from .types import SandboxConfiguration
|
11
11
|
|
12
12
|
|
13
|
+
class ProcessResponseWithLogs(ProcessResponse):
|
14
|
+
"""Extended ProcessResponse that adds a logs property."""
|
15
|
+
|
16
|
+
logs: Optional[str] = None
|
17
|
+
|
18
|
+
@classmethod
|
19
|
+
def from_process_response(cls, process_response: ProcessResponse, logs: Optional[str] = None):
|
20
|
+
"""Create ProcessResponseWithLogs from an existing ProcessResponse."""
|
21
|
+
# Create a new instance from the dict representation
|
22
|
+
instance = cls.from_dict(process_response.to_dict())
|
23
|
+
# Add the logs
|
24
|
+
instance.logs = logs
|
25
|
+
return instance
|
26
|
+
|
27
|
+
|
13
28
|
class SandboxProcess(SandboxAction):
|
14
29
|
def __init__(self, sandbox_config: SandboxConfiguration):
|
15
30
|
super().__init__(sandbox_config)
|
@@ -75,16 +90,56 @@ class SandboxProcess(SandboxAction):
|
|
75
90
|
|
76
91
|
return {"close": close}
|
77
92
|
|
78
|
-
async def exec(
|
93
|
+
async def exec(
|
94
|
+
self,
|
95
|
+
process: Union[ProcessRequest, Dict[str, Any]],
|
96
|
+
on_log: Optional[Callable[[str], None]] = None,
|
97
|
+
) -> ProcessResponseWithLogs:
|
79
98
|
if isinstance(process, dict):
|
80
99
|
process = ProcessRequest.from_dict(process)
|
81
100
|
|
82
101
|
async with self.get_client() as client_instance:
|
83
102
|
response = await client_instance.post("/process", json=process.to_dict())
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
103
|
+
|
104
|
+
# Parse JSON response only once, with better error handling
|
105
|
+
response_data = None
|
106
|
+
if response.content:
|
107
|
+
try:
|
108
|
+
response_data = response.json()
|
109
|
+
except Exception:
|
110
|
+
# If JSON parsing fails, check the response first
|
111
|
+
self.handle_response_error(response, None, None)
|
112
|
+
raise
|
113
|
+
|
114
|
+
self.handle_response_error(response, response_data, None)
|
115
|
+
result = ProcessResponse.from_dict(response_data)
|
116
|
+
|
117
|
+
# Setup log streaming if on_log is provided
|
118
|
+
stream_control = None
|
119
|
+
if on_log is not None:
|
120
|
+
stream_control = self.stream_logs(result.pid, {"on_log": on_log})
|
121
|
+
|
122
|
+
# Wait for completion if requested
|
123
|
+
logs = None
|
124
|
+
if process.wait_for_completion:
|
125
|
+
try:
|
126
|
+
# Wait for process to complete
|
127
|
+
result = await self.wait(result.pid)
|
128
|
+
|
129
|
+
# Get the logs
|
130
|
+
logs = await self.logs(result.pid, "all")
|
131
|
+
except Exception as e:
|
132
|
+
# If waiting fails, still try to return what we have
|
133
|
+
if stream_control:
|
134
|
+
stream_control["close"]()
|
135
|
+
raise e
|
136
|
+
|
137
|
+
# Close stream if it was opened and we're done
|
138
|
+
if stream_control and process.wait_for_completion:
|
139
|
+
stream_control["close"]()
|
140
|
+
|
141
|
+
# Return wrapped response with logs
|
142
|
+
return ProcessResponseWithLogs.from_process_response(result, logs)
|
88
143
|
|
89
144
|
async def wait(
|
90
145
|
self, identifier: str, max_wait: int = 60000, interval: int = 1000
|
@@ -309,7 +309,7 @@ blaxel/core/sandbox/action.py,sha256=9Zjkco7YkLzBThD3N2Hr5SpeEiqU_-Ktk8HlKpkpiAg
|
|
309
309
|
blaxel/core/sandbox/filesystem.py,sha256=dyIvDdlPZO0ijD6mXXX8Yl0t75VijQ6_uMz_9rJd-_4,11317
|
310
310
|
blaxel/core/sandbox/network.py,sha256=P5jLd4AAg1zgyIK4qGWvZaDZ5BzIcxRx2ffz_JLsLMI,357
|
311
311
|
blaxel/core/sandbox/preview.py,sha256=M6FulOxPghUBpb5fLxu1Rd3ekLeCbZ_dgt4s1X2Cneo,5354
|
312
|
-
blaxel/core/sandbox/process.py,sha256=
|
312
|
+
blaxel/core/sandbox/process.py,sha256=jgOPL5yLzhd98CLO7nBUABIAPFK5S5z34h6L_TyXsuU,8753
|
313
313
|
blaxel/core/sandbox/sandbox.py,sha256=tsRGvkb2dnGM5pmOiIxWvOmT42P9BDXWtW3h6_CIffI,5802
|
314
314
|
blaxel/core/sandbox/session.py,sha256=4SH1tyXcQ9UqJx4lMwxAlp7x9Te_anDrdSEG6AlNkvU,4496
|
315
315
|
blaxel/core/sandbox/types.py,sha256=gmNAt8x7PrJZHpw2_2aWWDE5uG6H-uEgdIKTYIw4G0g,2981
|
@@ -402,7 +402,7 @@ blaxel/telemetry/instrumentation/map.py,sha256=PCzZJj39yiYVYJrxLBNP-NW-tjjYyTijw
|
|
402
402
|
blaxel/telemetry/instrumentation/utils.py,sha256=KInMYZH-mu9_wvetmf0EmgrfN3Sw8IWk2Y95v2u90_U,1901
|
403
403
|
blaxel/telemetry/log/log.py,sha256=RvQByRjZMoP_dRaAZu8oK6DTegsHs-xV4W-UIqis6CA,2461
|
404
404
|
blaxel/telemetry/log/logger.py,sha256=NPAS3g82ryROjvc_DEZaTIfrcehoLEZoP-JkLxADxc0,4113
|
405
|
-
blaxel-0.2.
|
406
|
-
blaxel-0.2.
|
407
|
-
blaxel-0.2.
|
408
|
-
blaxel-0.2.
|
405
|
+
blaxel-0.2.1rc73.dist-info/METADATA,sha256=7M9mgqu97Tyk403KOchTBU9BzUlFHr8VXZ6JkuC0riM,9879
|
406
|
+
blaxel-0.2.1rc73.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
407
|
+
blaxel-0.2.1rc73.dist-info/licenses/LICENSE,sha256=p5PNQvpvyDT_0aYBDgmV1fFI_vAD2aSV0wWG7VTgRis,1069
|
408
|
+
blaxel-0.2.1rc73.dist-info/RECORD,,
|
File without changes
|
File without changes
|