I am trying to set up the Atari game environment and it's been a few hours that I am trying to understand why my render won't close after calling env.close()
.
When I call env.close()
, the render displays Visual Studio Code is not responding. Force Quit or Wait
. I have seen a couple stackoverflow articles proposing the use of pygame.quit()
but I have no success.
Here is my code, help would be appreciated:
import gym
from stable_baselines3 import a2c
from stable_baselines3.common.vec_env import VecFrameStack
from stable_baselines3.common.env_util import make_atari_env
from stable_baselines3.common.evaluation import evaluate_policy
import os
import pygame
environment_name = 'Breakout-v4'
env = gym.make(environment_name, render_mode='human')
# env.unwrapped.get_action_meanings()
env.metadata['render_fps'] = 150 # Or whichever fps value you prefer
env.reset()
episodes = 1
for episode in range (1, episodes+1):
obs = env.reset()
done = False
score = 0
while not done:
env.render()
action = env.action_space.sample()
n_state, reward, done, truncated, info = env.step(action)
score+=reward
print('Episode:{} Score:{}'.format(episode, score))
pygame.quit()
env.close()
I have tried to close the environment with env.close
and pygame.quit()
and I am expecting that the render window disappear.