langfun 0.1.2.dev202510300805__py3-none-any.whl → 0.1.2.dev202511010804__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 langfun might be problematic. Click here for more details.

@@ -1,350 +0,0 @@
1
-
2
- # Copyright 2025 The Langfun Authors
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- """Base classes for Langfun environment event handlers."""
16
-
17
- from langfun.env import interface
18
-
19
- Environment = interface.Environment
20
- Sandbox = interface.Sandbox
21
- Feature = interface.Feature
22
-
23
-
24
- class _SessionEventHandler:
25
- """Base class for session event handlers."""
26
-
27
- def on_session_start(
28
- self,
29
- environment: Environment,
30
- sandbox: Sandbox,
31
- session_id: str,
32
- duration: float,
33
- error: BaseException | None
34
- ) -> None:
35
- """Called when a sandbox session starts.
36
-
37
- Args:
38
- environment: The environment.
39
- sandbox: The sandbox.
40
- session_id: The session ID.
41
- duration: The time spent on starting the session.
42
- error: The error that caused the session to start. If None, the session
43
- started normally.
44
- """
45
-
46
- def on_session_end(
47
- self,
48
- environment: Environment,
49
- sandbox: Sandbox,
50
- session_id: str,
51
- duration: float,
52
- lifetime: float,
53
- error: BaseException | None
54
- ) -> None:
55
- """Called when a sandbox session ends.
56
-
57
- Args:
58
- environment: The environment.
59
- sandbox: The sandbox.
60
- session_id: The session ID.
61
- duration: The time spent on ending the session.
62
- lifetime: The session lifetime in seconds.
63
- error: The error that caused the session to end. If None, the session
64
- ended normally.
65
- """
66
-
67
-
68
- class _FeatureEventHandler:
69
- """Base class for feature event handlers."""
70
-
71
- def on_feature_setup(
72
- self,
73
- environment: Environment,
74
- sandbox: Sandbox,
75
- feature: Feature,
76
- duration: float,
77
- error: BaseException | None
78
- ) -> None:
79
- """Called when a sandbox feature is setup.
80
-
81
- Args:
82
- environment: The environment.
83
- sandbox: The sandbox.
84
- feature: The feature.
85
- duration: The feature setup duration in seconds.
86
- error: The error happened during the feature setup. If None,
87
- the feature setup performed normally.
88
- """
89
-
90
- def on_feature_teardown(
91
- self,
92
- environment: Environment,
93
- sandbox: Sandbox,
94
- feature: Feature,
95
- duration: float,
96
- error: BaseException | None
97
- ) -> None:
98
- """Called when a sandbox feature is teardown.
99
-
100
- Args:
101
- environment: The environment.
102
- sandbox: The sandbox.
103
- feature: The feature.
104
- duration: The feature teardown duration in seconds.
105
- error: The error happened during the feature teardown. If None,
106
- the feature teardown performed normally.
107
- """
108
-
109
- def on_feature_teardown_session(
110
- self,
111
- environment: Environment,
112
- sandbox: Sandbox,
113
- feature: Feature,
114
- session_id: str,
115
- duration: float,
116
- error: BaseException | None
117
- ) -> None:
118
- """Called when a feature is teardown with a session.
119
-
120
- Args:
121
- environment: The environment.
122
- sandbox: The sandbox.
123
- feature: The feature.
124
- session_id: The session ID.
125
- duration: The feature teardown session duration in seconds.
126
- error: The error happened during the feature teardown session. If
127
- None, the feature teardown session performed normally.
128
- """
129
-
130
- def on_feature_setup_session(
131
- self,
132
- environment: Environment,
133
- sandbox: Sandbox,
134
- feature: Feature,
135
- session_id: str | None,
136
- duration: float,
137
- error: BaseException | None,
138
- ) -> None:
139
- """Called when a feature is setup with a session.
140
-
141
- Args:
142
- environment: The environment.
143
- sandbox: The sandbox.
144
- feature: The feature.
145
- session_id: The session ID.
146
- duration: The feature setup session duration in seconds.
147
- error: The error happened during the feature setup session. If
148
- None, the feature setup session performed normally.
149
- """
150
-
151
- def on_feature_housekeep(
152
- self,
153
- environment: Environment,
154
- sandbox: Sandbox,
155
- feature: Feature,
156
- counter: int,
157
- duration: float,
158
- error: BaseException | None,
159
- **kwargs,
160
- ) -> None:
161
- """Called when a sandbox feature is housekeeping.
162
-
163
- Args:
164
- environment: The environment.
165
- sandbox: The sandbox.
166
- feature: The feature.
167
- counter: Zero-based counter of the housekeeping round.
168
- duration: The feature housekeeping duration in seconds.
169
- error: The error happened during the feature housekeeping. If None, the
170
- feature housekeeping normally.
171
- **kwargs: Feature-specific properties computed during housekeeping.
172
- """
173
-
174
-
175
- class _SandboxEventHandler(_FeatureEventHandler, _SessionEventHandler):
176
- """Base class for sandbox event handlers."""
177
-
178
- def on_sandbox_start(
179
- self,
180
- environment: Environment,
181
- sandbox: Sandbox,
182
- duration: float,
183
- error: BaseException | None
184
- ) -> None:
185
- """Called when a sandbox is started.
186
-
187
- Args:
188
- environment: The environment.
189
- sandbox: The sandbox.
190
- duration: The time spent on starting the sandbox.
191
- error: The error that caused the sandbox to start. If None, the sandbox
192
- started normally.
193
- """
194
-
195
- def on_sandbox_status_change(
196
- self,
197
- environment: Environment,
198
- sandbox: Sandbox,
199
- old_status: 'Sandbox.Status',
200
- new_status: 'Sandbox.Status',
201
- span: float,
202
- ) -> None:
203
- """Called when a sandbox status changes.
204
-
205
- Args:
206
- environment: The environment.
207
- sandbox: The sandbox.
208
- old_status: The old sandbox status.
209
- new_status: The new sandbox status.
210
- span: Time spent on the old status in seconds.
211
- """
212
-
213
- def on_sandbox_shutdown(
214
- self,
215
- environment: Environment,
216
- sandbox: Sandbox,
217
- duration: float,
218
- lifetime: float,
219
- error: BaseException | None
220
- ) -> None:
221
- """Called when a sandbox is shutdown.
222
-
223
- Args:
224
- environment: The environment.
225
- sandbox: The sandbox.
226
- duration: The time spent on shutting down the sandbox.
227
- lifetime: The sandbox lifetime in seconds.
228
- error: The error that caused the sandbox to shutdown. If None, the
229
- sandbox shutdown normally.
230
- """
231
-
232
- def on_sandbox_activity(
233
- self,
234
- name: str,
235
- environment: Environment,
236
- sandbox: Sandbox,
237
- feature: Feature | None,
238
- session_id: str | None,
239
- duration: float,
240
- error: BaseException | None,
241
- **kwargs
242
- ) -> None:
243
- """Called when a sandbox activity is performed.
244
-
245
- Args:
246
- name: The name of the sandbox activity.
247
- environment: The environment.
248
- sandbox: The sandbox.
249
- feature: The feature that is associated with the sandbox activity.
250
- session_id: The session ID.
251
- duration: The sandbox activity duration in seconds.
252
- error: The error that caused the sandbox activity to perform. If None,
253
- the sandbox activity performed normally.
254
- **kwargs: The keyword arguments of the sandbox activity.
255
- """
256
-
257
- def on_sandbox_housekeep(
258
- self,
259
- environment: Environment,
260
- sandbox: Sandbox,
261
- counter: int,
262
- duration: float,
263
- error: BaseException | None,
264
- **kwargs
265
- ) -> None:
266
- """Called when a sandbox finishes a round of housekeeping.
267
-
268
- Args:
269
- environment: The environment.
270
- sandbox: The sandbox.
271
- counter: Zero-based counter of the housekeeping round.
272
- duration: The sandbox housekeeping duration in seconds.
273
- error: The error that caused the sandbox to housekeeping. If None, the
274
- sandbox housekeeping normally.
275
- **kwargs: Sandbox-specific properties computed during housekeeping.
276
- """
277
-
278
-
279
- class EventHandler(_SandboxEventHandler):
280
- """Base class for event handlers of an environment."""
281
-
282
- def on_environment_starting(self, environment: Environment) -> None:
283
- """Called when the environment is getting started.
284
-
285
- Args:
286
- environment: The environment.
287
- """
288
-
289
- def on_environment_start(
290
- self,
291
- environment: Environment,
292
- duration: float,
293
- error: BaseException | None
294
- ) -> None:
295
- """Called when the environment is started.
296
-
297
- Args:
298
- environment: The environment.
299
- duration: The environment start duration in seconds.
300
- error: The error that failed the environment start. If None, the
301
- environment started normally.
302
- """
303
-
304
- def on_environment_housekeep(
305
- self,
306
- environment: Environment,
307
- counter: int,
308
- duration: float,
309
- error: BaseException | None,
310
- **kwargs
311
- ) -> None:
312
- """Called when the environment finishes a round of housekeeping.
313
-
314
- Args:
315
- environment: The environment.
316
- counter: Zero-based counter of the housekeeping round.
317
- duration: The environment start duration in seconds.
318
- error: The error that failed the housekeeping. If None, the
319
- housekeeping succeeded.
320
- **kwargs: Environment-specific properties computed during housekeeping.
321
- """
322
-
323
- def on_environment_shutting_down(
324
- self,
325
- environment: Environment,
326
- offline_duration: float,
327
- ) -> None:
328
- """Called when the environment is shutting down.
329
-
330
- Args:
331
- environment: The environment.
332
- offline_duration: The environment offline duration in seconds.
333
- """
334
-
335
- def on_environment_shutdown(
336
- self,
337
- environment: Environment,
338
- duration: float,
339
- lifetime: float,
340
- error: BaseException | None
341
- ) -> None:
342
- """Called when the environment is shutdown.
343
-
344
- Args:
345
- environment: The environment.
346
- duration: The environment shutdown duration in seconds.
347
- lifetime: The environment lifetime in seconds.
348
- error: The error that caused the environment to shutdown. If None, the
349
- environment shutdown normally.
350
- """