Skip to content

Commit 2749bb2

Browse files
authored
run_massage is not longer defined inside a function (#328)
1 parent dc55761 commit 2749bb2

File tree

1 file changed

+25
-24
lines changed
  • browsergym/experiments/src/browsergym/experiments/benchmark

1 file changed

+25
-24
lines changed

browsergym/experiments/src/browsergym/experiments/benchmark/utils.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,30 @@ def massage_tasks(task_ids: list[str], max_retries: int = 1, timeout: int = 60):
225225
)
226226

227227

228+
def run_massage(outcome_queue: mp.Queue, task_id: str):
229+
import gymnasium as gym
230+
231+
gym_id = f"browsergym/{task_id}"
232+
env = gym.make(gym_id)
233+
no_action = "noop()"
234+
# check if action space exists and is compatible with "noop()"
235+
try:
236+
env.unwrapped.action_mapping(no_action)
237+
except:
238+
no_action = "" # fallback plan
239+
# run massage
240+
try:
241+
env.reset() # task setup
242+
env.step(no_action) # task validation
243+
env.step(no_action) # task validation again
244+
outcome = "success", None
245+
except Exception as e:
246+
outcome = "exception", traceback.format_exception(e)
247+
finally:
248+
env.close()
249+
outcome_queue.put(outcome)
250+
251+
228252
def massage_task_within_subprocess(
229253
task_id: str, timeout: int, kill_timeout: int = 10
230254
) -> typing.Tuple[str, str]:
@@ -236,31 +260,8 @@ def massage_task_within_subprocess(
236260
- err_msg: error message if any, or None.
237261
"""
238262

239-
def run_massage(outcome_queue: mp.Queue):
240-
import gymnasium as gym
241-
242-
gym_id = f"browsergym/{task_id}"
243-
env = gym.make(gym_id)
244-
no_action = "noop()"
245-
# check if action space exists and is compatible with "noop()"
246-
try:
247-
env.unwrapped.action_mapping(no_action)
248-
except:
249-
no_action = "" # fallback plan
250-
# run massage
251-
try:
252-
env.reset() # task setup
253-
env.step(no_action) # task validation
254-
env.step(no_action) # task validation again
255-
outcome = "success", None
256-
except Exception as e:
257-
outcome = "exception", traceback.format_exception(e)
258-
finally:
259-
env.close()
260-
outcome_queue.put(outcome)
261-
262263
queue = mp.Queue()
263-
process = mp.Process(target=run_massage, args=(queue,))
264+
process = mp.Process(target=run_massage, args=(queue, task_id))
264265
process.start()
265266
process.join(timeout=timeout)
266267

0 commit comments

Comments
 (0)