diff --git a/stable_baselines3/common/env_checker.py b/stable_baselines3/common/env_checker.py index 116b297..6b387cc 100644 --- a/stable_baselines3/common/env_checker.py +++ b/stable_baselines3/common/env_checker.py @@ -380,6 +380,8 @@ def check_env(env: gym.Env, warn: bool = True, skip_render_check: bool = True) - It also optionally check that the environment is compatible with Stable-Baselines. + Note that this function eventually calls the close the environment. + :param env: The Gym environment that will be checked :param warn: Whether to output additional warnings mainly related to the interaction with Stable Baselines @@ -449,12 +451,8 @@ def check_env(env: gym.Env, warn: bool = True, skip_render_check: bool = True) - pass # Finally, check that the allows calling `close()` even if the environment was already closed - if env.spec is not None: - new_env = env.spec.make() - new_env.close() - try: - new_env.close() - except Exception as e: - warnings.warn( - f"Calling `env.close()` on the closed environment should be allowed, but it raised an exception: {e}" - ) + env.close() + try: + env.close() + except Exception as e: + warnings.warn(f"Calling `env.close()` on the closed environment should be allowed, but it raised an exception: {e}")