langfun 0.1.2.dev202509230805__py3-none-any.whl → 0.1.2.dev202509250804__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.
- langfun/env/__init__.py +1 -1
- langfun/env/base_environment.py +70 -39
- langfun/env/base_feature.py +25 -12
- langfun/env/base_sandbox.py +204 -74
- langfun/env/base_test.py +166 -399
- langfun/env/interface.py +167 -35
- langfun/env/test_utils.py +473 -0
- {langfun-0.1.2.dev202509230805.dist-info → langfun-0.1.2.dev202509250804.dist-info}/METADATA +1 -1
- {langfun-0.1.2.dev202509230805.dist-info → langfun-0.1.2.dev202509250804.dist-info}/RECORD +12 -11
- {langfun-0.1.2.dev202509230805.dist-info → langfun-0.1.2.dev202509250804.dist-info}/WHEEL +0 -0
- {langfun-0.1.2.dev202509230805.dist-info → langfun-0.1.2.dev202509250804.dist-info}/licenses/LICENSE +0 -0
- {langfun-0.1.2.dev202509230805.dist-info → langfun-0.1.2.dev202509250804.dist-info}/top_level.txt +0 -0
langfun/env/interface.py
CHANGED
|
@@ -230,30 +230,38 @@ class SessionEventHandler:
|
|
|
230
230
|
environment: 'Environment',
|
|
231
231
|
sandbox: 'Sandbox',
|
|
232
232
|
session_id: str,
|
|
233
|
+
duration: float,
|
|
233
234
|
error: BaseException | None
|
|
234
235
|
) -> None:
|
|
235
|
-
"""Called when a sandbox session starts.
|
|
236
|
+
"""Called when a sandbox session starts.
|
|
236
237
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
**kwargs
|
|
246
|
-
) -> None:
|
|
247
|
-
"""Called when a sandbox activity is performed."""
|
|
238
|
+
Args:
|
|
239
|
+
environment: The environment.
|
|
240
|
+
sandbox: The sandbox.
|
|
241
|
+
session_id: The session ID.
|
|
242
|
+
duration: The time spent on starting the session.
|
|
243
|
+
error: The error that caused the session to start. If None, the session
|
|
244
|
+
started normally.
|
|
245
|
+
"""
|
|
248
246
|
|
|
249
247
|
def on_session_end(
|
|
250
248
|
self,
|
|
251
249
|
environment: 'Environment',
|
|
252
250
|
sandbox: 'Sandbox',
|
|
253
251
|
session_id: str,
|
|
252
|
+
lifetime: float,
|
|
254
253
|
error: BaseException | None
|
|
255
254
|
) -> None:
|
|
256
|
-
"""Called when a sandbox session ends.
|
|
255
|
+
"""Called when a sandbox session ends.
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
environment: The environment.
|
|
259
|
+
sandbox: The sandbox.
|
|
260
|
+
session_id: The session ID.
|
|
261
|
+
lifetime: The session lifetime in seconds.
|
|
262
|
+
error: The error that caused the session to end. If None, the session
|
|
263
|
+
ended normally.
|
|
264
|
+
"""
|
|
257
265
|
|
|
258
266
|
|
|
259
267
|
class FeatureEventHandler:
|
|
@@ -264,6 +272,7 @@ class FeatureEventHandler:
|
|
|
264
272
|
environment: 'Environment',
|
|
265
273
|
sandbox: 'Sandbox',
|
|
266
274
|
feature: 'Feature',
|
|
275
|
+
duration: float,
|
|
267
276
|
error: BaseException | None
|
|
268
277
|
) -> None:
|
|
269
278
|
"""Called when a sandbox feature is setup."""
|
|
@@ -273,6 +282,7 @@ class FeatureEventHandler:
|
|
|
273
282
|
environment: 'Environment',
|
|
274
283
|
sandbox: 'Sandbox',
|
|
275
284
|
feature: 'Feature',
|
|
285
|
+
duration: float,
|
|
276
286
|
error: BaseException | None
|
|
277
287
|
) -> None:
|
|
278
288
|
"""Called when a sandbox feature is teardown."""
|
|
@@ -283,6 +293,7 @@ class FeatureEventHandler:
|
|
|
283
293
|
sandbox: 'Sandbox',
|
|
284
294
|
feature: 'Feature',
|
|
285
295
|
session_id: str,
|
|
296
|
+
duration: float,
|
|
286
297
|
error: BaseException | None
|
|
287
298
|
) -> None:
|
|
288
299
|
"""Called when a feature is teardown with a session."""
|
|
@@ -293,6 +304,7 @@ class FeatureEventHandler:
|
|
|
293
304
|
sandbox: 'Sandbox',
|
|
294
305
|
feature: 'Feature',
|
|
295
306
|
session_id: str | None,
|
|
307
|
+
duration: float,
|
|
296
308
|
error: BaseException | None
|
|
297
309
|
) -> None:
|
|
298
310
|
"""Called when a feature is setup with a session."""
|
|
@@ -302,6 +314,8 @@ class FeatureEventHandler:
|
|
|
302
314
|
environment: 'Environment',
|
|
303
315
|
sandbox: 'Sandbox',
|
|
304
316
|
feature: 'Feature',
|
|
317
|
+
counter: int,
|
|
318
|
+
duration: float,
|
|
305
319
|
error: BaseException | None
|
|
306
320
|
) -> None:
|
|
307
321
|
"""Called when a sandbox feature is housekeeping."""
|
|
@@ -314,9 +328,18 @@ class SandboxEventHandler(FeatureEventHandler, SessionEventHandler):
|
|
|
314
328
|
self,
|
|
315
329
|
environment: 'Environment',
|
|
316
330
|
sandbox: 'Sandbox',
|
|
331
|
+
duration: float,
|
|
317
332
|
error: BaseException | None
|
|
318
333
|
) -> None:
|
|
319
|
-
"""Called when a sandbox is started.
|
|
334
|
+
"""Called when a sandbox is started.
|
|
335
|
+
|
|
336
|
+
Args:
|
|
337
|
+
environment: The environment.
|
|
338
|
+
sandbox: The sandbox.
|
|
339
|
+
duration: The time spent on starting the sandbox.
|
|
340
|
+
error: The error that caused the sandbox to start. If None, the sandbox
|
|
341
|
+
started normally.
|
|
342
|
+
"""
|
|
320
343
|
|
|
321
344
|
def on_sandbox_status_change(
|
|
322
345
|
self,
|
|
@@ -324,16 +347,78 @@ class SandboxEventHandler(FeatureEventHandler, SessionEventHandler):
|
|
|
324
347
|
sandbox: 'Sandbox',
|
|
325
348
|
old_status: 'Sandbox.Status',
|
|
326
349
|
new_status: 'Sandbox.Status',
|
|
350
|
+
span: float,
|
|
327
351
|
) -> None:
|
|
328
|
-
"""Called when a sandbox status changes.
|
|
352
|
+
"""Called when a sandbox status changes.
|
|
353
|
+
|
|
354
|
+
Args:
|
|
355
|
+
environment: The environment.
|
|
356
|
+
sandbox: The sandbox.
|
|
357
|
+
old_status: The old sandbox status.
|
|
358
|
+
new_status: The new sandbox status.
|
|
359
|
+
span: Time spent on the old status in seconds.
|
|
360
|
+
"""
|
|
329
361
|
|
|
330
362
|
def on_sandbox_shutdown(
|
|
331
363
|
self,
|
|
332
364
|
environment: 'Environment',
|
|
333
365
|
sandbox: 'Sandbox',
|
|
366
|
+
lifetime: float,
|
|
367
|
+
error: BaseException | None
|
|
368
|
+
) -> None:
|
|
369
|
+
"""Called when a sandbox is shutdown.
|
|
370
|
+
|
|
371
|
+
Args:
|
|
372
|
+
environment: The environment.
|
|
373
|
+
sandbox: The sandbox.
|
|
374
|
+
lifetime: The sandbox lifetime in seconds.
|
|
375
|
+
error: The error that caused the sandbox to shutdown. If None, the
|
|
376
|
+
sandbox shutdown normally.
|
|
377
|
+
"""
|
|
378
|
+
|
|
379
|
+
def on_sandbox_activity(
|
|
380
|
+
self,
|
|
381
|
+
name: str,
|
|
382
|
+
environment: 'Environment',
|
|
383
|
+
sandbox: 'Sandbox',
|
|
384
|
+
feature: Optional['Feature'],
|
|
385
|
+
session_id: str | None,
|
|
386
|
+
duration: float,
|
|
387
|
+
error: BaseException | None,
|
|
388
|
+
**kwargs
|
|
389
|
+
) -> None:
|
|
390
|
+
"""Called when a sandbox activity is performed.
|
|
391
|
+
|
|
392
|
+
Args:
|
|
393
|
+
name: The name of the sandbox activity.
|
|
394
|
+
environment: The environment.
|
|
395
|
+
sandbox: The sandbox.
|
|
396
|
+
feature: The feature that is associated with the sandbox activity.
|
|
397
|
+
session_id: The session ID.
|
|
398
|
+
duration: The sandbox activity duration in seconds.
|
|
399
|
+
error: The error that caused the sandbox activity to perform. If None,
|
|
400
|
+
the sandbox activity performed normally.
|
|
401
|
+
**kwargs: The keyword arguments of the sandbox activity.
|
|
402
|
+
"""
|
|
403
|
+
|
|
404
|
+
def on_sandbox_housekeep(
|
|
405
|
+
self,
|
|
406
|
+
environment: 'Environment',
|
|
407
|
+
sandbox: 'Sandbox',
|
|
408
|
+
counter: int,
|
|
409
|
+
duration: float,
|
|
334
410
|
error: BaseException | None
|
|
335
411
|
) -> None:
|
|
336
|
-
"""Called when a sandbox
|
|
412
|
+
"""Called when a sandbox finishes a round of housekeeping.
|
|
413
|
+
|
|
414
|
+
Args:
|
|
415
|
+
environment: The environment.
|
|
416
|
+
sandbox: The sandbox.
|
|
417
|
+
counter: Zero-based counter of the housekeeping round.
|
|
418
|
+
duration: The sandbox housekeeping duration in seconds.
|
|
419
|
+
error: The error that caused the sandbox to housekeeping. If None, the
|
|
420
|
+
sandbox housekeeping normally.
|
|
421
|
+
"""
|
|
337
422
|
|
|
338
423
|
|
|
339
424
|
class EnvironmentEventHandler(SandboxEventHandler):
|
|
@@ -342,16 +427,49 @@ class EnvironmentEventHandler(SandboxEventHandler):
|
|
|
342
427
|
def on_environment_start(
|
|
343
428
|
self,
|
|
344
429
|
environment: 'Environment',
|
|
430
|
+
duration: float,
|
|
345
431
|
error: BaseException | None
|
|
346
432
|
) -> None:
|
|
347
|
-
"""Called when the environment is started.
|
|
433
|
+
"""Called when the environment is started.
|
|
434
|
+
|
|
435
|
+
Args:
|
|
436
|
+
environment: The environment.
|
|
437
|
+
duration: The environment start duration in seconds.
|
|
438
|
+
error: The error that failed the environment start. If None, the
|
|
439
|
+
environment started normally.
|
|
440
|
+
"""
|
|
441
|
+
|
|
442
|
+
def on_environment_housekeep(
|
|
443
|
+
self,
|
|
444
|
+
environment: 'Environment',
|
|
445
|
+
counter: int,
|
|
446
|
+
duration: float,
|
|
447
|
+
error: BaseException | None
|
|
448
|
+
) -> None:
|
|
449
|
+
"""Called when the environment finishes a round of housekeeping.
|
|
450
|
+
|
|
451
|
+
Args:
|
|
452
|
+
environment: The environment.
|
|
453
|
+
counter: Zero-based counter of the housekeeping round.
|
|
454
|
+
duration: The environment start duration in seconds.
|
|
455
|
+
error: The error that failed the housekeeping. If None, the
|
|
456
|
+
housekeeping succeeded.
|
|
457
|
+
"""
|
|
348
458
|
|
|
349
459
|
def on_environment_shutdown(
|
|
350
460
|
self,
|
|
351
461
|
environment: 'Environment',
|
|
462
|
+
lifetime: float,
|
|
352
463
|
error: BaseException | None
|
|
353
464
|
) -> None:
|
|
354
|
-
"""Called when the environment is shutdown.
|
|
465
|
+
"""Called when the environment is shutdown.
|
|
466
|
+
|
|
467
|
+
Args:
|
|
468
|
+
environment: The environment.
|
|
469
|
+
lifetime: The environment lifetime in seconds.
|
|
470
|
+
error: The error that caused the environment to shutdown. If None, the
|
|
471
|
+
environment shutdown normally.
|
|
472
|
+
"""
|
|
355
473
|
|
|
356
474
|
|
|
357
475
|
#
|
|
@@ -534,21 +652,28 @@ class Sandbox(pg.Object):
|
|
|
534
652
|
| | |
|
|
535
653
|
| (set_acquired) | |
|
|
536
654
|
v | |
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
655
|
+
+----------+ | |
|
|
656
|
+
| ACQUIRED | | |
|
|
657
|
+
+----------+ | |
|
|
540
658
|
| | |
|
|
541
659
|
| (call start_session) | |
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
660
|
+
+------------+ | |
|
|
661
|
+
| SETTING_UP |--(failed, call shutdown)-+
|
|
662
|
+
+------------+ | |
|
|
545
663
|
| | |
|
|
546
|
-
v
|
|
664
|
+
v (succeeded) | |
|
|
547
665
|
+--------------+ | |
|
|
548
|
-
| IN_SESSION
|
|
549
|
-
+--------------+
|
|
666
|
+
| IN_SESSION | | |
|
|
667
|
+
+--------------+ | |
|
|
668
|
+
| | |
|
|
669
|
+
(call end_session) | |
|
|
670
|
+
| | |
|
|
671
|
+
v | |
|
|
672
|
+
+-----------------+ | |
|
|
673
|
+
| EXITING_SESSION |--(succeeded)--+ |
|
|
674
|
+
+-----------------+ |
|
|
550
675
|
| |
|
|
551
|
-
+------(shutdown)
|
|
676
|
+
+------(failed, call shutdown)--+
|
|
552
677
|
"""
|
|
553
678
|
|
|
554
679
|
# The sandbox is created, but not yet started.
|
|
@@ -566,6 +691,9 @@ class Sandbox(pg.Object):
|
|
|
566
691
|
# The sandbox is in a user session.
|
|
567
692
|
IN_SESSION = 'in_session'
|
|
568
693
|
|
|
694
|
+
# The sandbox is exiting a user session.
|
|
695
|
+
EXITING_SESSION = 'exiting_session'
|
|
696
|
+
|
|
569
697
|
# The sandbox is being shut down.
|
|
570
698
|
SHUTTING_DOWN = 'shutting_down'
|
|
571
699
|
|
|
@@ -742,14 +870,18 @@ class Sandbox(pg.Object):
|
|
|
742
870
|
"""Ends the user session with the sandbox.
|
|
743
871
|
|
|
744
872
|
State transitions:
|
|
745
|
-
IN_SESSION -> READY: When user session exits normally,
|
|
746
|
-
to reuse.
|
|
747
|
-
IN_SESSION -> SHUTTING_DOWN -> OFFLINE: When user
|
|
873
|
+
IN_SESSION -> EXITING_SESSION -> READY: When user session exits normally,
|
|
874
|
+
and sandbox is set to reuse.
|
|
875
|
+
IN_SESSION -> EXITING_SESSION -> SHUTTING_DOWN -> OFFLINE: When user
|
|
876
|
+
session exits while
|
|
748
877
|
sandbox is set not to reuse, or session teardown fails.
|
|
749
|
-
IN_SESSION -> SETTING_UP -> READY: When user session
|
|
750
|
-
sandbox is set to reuse, and proactive session setup
|
|
751
|
-
|
|
752
|
-
|
|
878
|
+
IN_SESSION -> EXITING_SESSION -> SETTING_UP -> READY: When user session
|
|
879
|
+
exits normally, and sandbox is set to reuse, and proactive session setup
|
|
880
|
+
is enabled.
|
|
881
|
+
IN_SESSION -> EXITING_SESSION -> SETTING_UP -> SHUTTING_DOWN -> OFFLINE:
|
|
882
|
+
When user session exits normally, and proactive session setup is enabled
|
|
883
|
+
but fails.
|
|
884
|
+
EXITING_SESSION -> EXITING_SESSION: No operation.
|
|
753
885
|
not IN_SESSION -> same state: No operation
|
|
754
886
|
|
|
755
887
|
`end_session` should always be called for each `start_session` call, even
|