langfun 0.1.2.dev202509170804__py3-none-any.whl → 0.1.2.dev202509180804__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 CHANGED
@@ -35,3 +35,5 @@ from langfun.env.base_feature import BaseFeature
35
35
 
36
36
  from langfun.env import load_balancers
37
37
  from langfun.env.load_balancers import LoadBalancer
38
+
39
+ # Google-internal imports.
@@ -105,8 +105,9 @@ class BaseFeature(interface.Feature):
105
105
  self.__dict__.pop('name', None)
106
106
 
107
107
  @property
108
- def sandbox(self) -> interface.Sandbox | None:
108
+ def sandbox(self) -> interface.Sandbox:
109
109
  """Returns the sandbox that the feature is running in."""
110
+ assert self._sandbox is not None, 'Feature has not been set up yet.'
110
111
  return self._sandbox
111
112
 
112
113
  #
@@ -123,6 +124,12 @@ class BaseFeature(interface.Feature):
123
124
 
124
125
  def teardown(self) -> None:
125
126
  """Tears down the feature."""
127
+ # If a sandbox is down during setting up, feature.shutdown might be called
128
+ # before the feature is setup. In this case, we don't need to teardown the
129
+ # feature.
130
+ if self._sandbox is None:
131
+ return
132
+
126
133
  interface.call_with_event(
127
134
  action=self._teardown,
128
135
  event_handler=self.on_teardown,
@@ -91,14 +91,24 @@ class BaseSandbox(interface.Sandbox):
91
91
  def _start_session(self, session_id: str) -> None:
92
92
  """Starts a user session."""
93
93
  self._session_id = session_id
94
+ self._session_start_time = time.time()
95
+
94
96
  for feature in self._features.values():
95
97
  feature.setup_session(session_id)
96
98
 
97
99
  def _end_session(self) -> None:
98
- """Ends the user session with the sandbox."""
99
- for feature in self._features.values():
100
- feature.teardown_session(self._session_id)
101
- self._session_id = None
100
+ try:
101
+ for feature in self._features.values():
102
+ feature.teardown_session(self._session_id)
103
+ finally:
104
+ pg.logging.info(
105
+ '[%s]: User session %s ended. (lifetime: %.2f seconds).',
106
+ self.id,
107
+ self._session_id,
108
+ time.time() - self._session_start_time
109
+ )
110
+ self._session_id = None
111
+ self._session_start_time = None
102
112
 
103
113
  def _ping(self) -> None:
104
114
  """Implementation of ping for health checking."""
@@ -115,6 +125,7 @@ class BaseSandbox(interface.Sandbox):
115
125
  for name, feature in self.environment.features.items()
116
126
  })
117
127
  self._session_id = None
128
+ self._session_start_time = None
118
129
  self._alive = False
119
130
  self._start_time = None
120
131
 
@@ -197,6 +208,7 @@ class BaseSandbox(interface.Sandbox):
197
208
  return
198
209
 
199
210
  self._alive = False
211
+ shutdown_start_time = time.time()
200
212
  def shutdown_impl():
201
213
  self._teardown_features()
202
214
  self._shutdown()
@@ -205,8 +217,10 @@ class BaseSandbox(interface.Sandbox):
205
217
  self._housekeep_thread.join()
206
218
  self._housekeep_thread = None
207
219
  pg.logging.info(
208
- '[%s]: Sandbox shutdown in %.2f seconds.',
209
- self.id, time.time() - self._start_time
220
+ '[%s]: Sandbox shutdown in %.2f seconds. (lifetime: %.2f seconds)',
221
+ self.id,
222
+ time.time() - shutdown_start_time,
223
+ time.time() - self._start_time if self._start_time else 0
210
224
  )
211
225
 
212
226
  interface.call_with_event(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langfun
3
- Version: 0.1.2.dev202509170804
3
+ Version: 0.1.2.dev202509180804
4
4
  Summary: Langfun: Language as Functions.
5
5
  Home-page: https://github.com/google/langfun
6
6
  Author: Langfun Authors
@@ -165,17 +165,17 @@ langfun/core/templates/demonstration.py,sha256=vCrgYubdZM5Umqcgp8NUVGXgr4P_c-fik
165
165
  langfun/core/templates/demonstration_test.py,sha256=SafcDQ0WgI7pw05EmPI2S4v1t3ABKzup8jReCljHeK4,2162
166
166
  langfun/core/templates/selfplay.py,sha256=yhgrJbiYwq47TgzThmHrDQTF4nDrTI09CWGhuQPNv-s,2273
167
167
  langfun/core/templates/selfplay_test.py,sha256=Ot__1P1M8oJfoTp-M9-PQ6HUXqZKyMwvZ5f7yQ3yfyM,2326
168
- langfun/env/__init__.py,sha256=zgiONH9pIpNTEL623jRmW2mMI-GhThzEegZoys_znrQ,1554
168
+ langfun/env/__init__.py,sha256=YB44mvoCNiqWP48ITExQKZ3yHGoskFGB1pYRUEwWdbc,1582
169
169
  langfun/env/base_environment.py,sha256=BMdSpsk0uMCPklrZ7XQPpJ03IL3ZEzCIs3RlUfG8yNo,14215
170
- langfun/env/base_feature.py,sha256=SVvgoA68vafZZct5ZuHjPHblrCVv2Es4bLg5wgVTMww,4653
171
- langfun/env/base_sandbox.py,sha256=oSuUSd3zVgBxH14r9uX9SelyoXHzQQWzGHEiain8eKo,13690
170
+ langfun/env/base_feature.py,sha256=C3s9ovV7MPOBGNM9evfABVkGxcfazX8A03Jb_RB1MW0,4936
171
+ langfun/env/base_sandbox.py,sha256=SWDU3Mez7FVctpMwePbcavru3GkdTsC59neWz8MqTis,14126
172
172
  langfun/env/base_test.py,sha256=FuytEQJeKnxX_VEW0axdEoCg1A1d2rIVQss0qxoPPAQ,26739
173
173
  langfun/env/interface.py,sha256=4Q6ewOtj8XJyy8OEQqSYwogjzfvivFOljGS5txhlx_U,21534
174
174
  langfun/env/interface_test.py,sha256=nrqFLtpHd0vnOjoIX9cjV5WD1c-7J3WW29aogNu_94A,1395
175
175
  langfun/env/load_balancers.py,sha256=jbT3pB7QpPVovbXeJK1PNohUcrYrJNtWU8KaWzxO9nI,1963
176
176
  langfun/env/load_balancers_test.py,sha256=bAjC89zxmROpkl56BqvMU_yKOJ03Gtu8x8j56HO5HNc,4124
177
- langfun-0.1.2.dev202509170804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
178
- langfun-0.1.2.dev202509170804.dist-info/METADATA,sha256=Ps_Bme20ro1JnbT4nQj2Cs-euv4K-DpwcTg4BQr37u4,7380
179
- langfun-0.1.2.dev202509170804.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
180
- langfun-0.1.2.dev202509170804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
181
- langfun-0.1.2.dev202509170804.dist-info/RECORD,,
177
+ langfun-0.1.2.dev202509180804.dist-info/licenses/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
178
+ langfun-0.1.2.dev202509180804.dist-info/METADATA,sha256=bdpN3vONnVYkei_3FGJQK7ohVxjle5cLnb3Gb_kgjyc,7380
179
+ langfun-0.1.2.dev202509180804.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
180
+ langfun-0.1.2.dev202509180804.dist-info/top_level.txt,sha256=RhlEkHxs1qtzmmtWSwYoLVJAc1YrbPtxQ52uh8Z9VvY,8
181
+ langfun-0.1.2.dev202509180804.dist-info/RECORD,,