From fcabae31f46ad3c9f89f6d2e7e64eed8fca6c965 Mon Sep 17 00:00:00 2001 From: Misha Lvovsky Date: Fri, 19 Jan 2024 10:46:22 -0500 Subject: [PATCH] add multiproc test --- tests/envs/maze/test_point_maze.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/envs/maze/test_point_maze.py b/tests/envs/maze/test_point_maze.py index e2204891..cdb8ec30 100644 --- a/tests/envs/maze/test_point_maze.py +++ b/tests/envs/maze/test_point_maze.py @@ -39,3 +39,23 @@ def test_goal_cell(): obs = env.reset(options={"goal_cell": [2, 1]}, seed=42)[0] desired_goal = np.array([-0.36302198, -0.53056078]) np.testing.assert_almost_equal(desired_goal, obs["desired_goal"], decimal=4) + + +def test_multiprocessing(): + """Check that the environment can be used in a multiprocessing environment.""" + import multiprocessing as mp + + def run_env(): + env = gym.make("PointMaze_UMaze-v3") + env.reset() + for _ in range(100): + env.step(env.action_space.sample()) + + processes = [] + for _ in range(4): + p = mp.Process(target=run_env) + p.start() + processes.append(p) + + for p in processes: + p.join()