Closed jake-sanvito closed 6 years ago
I think you should use env.close()
whenever you want to close the window
@tinyalpha, calling env.close()
closes the environment freeing up all the physics' state resources, requiring to gym.make()
the environment again. Since, there is a functionality to reset the environment by env.reset()
without closing and remaking the environment, it would be really beneficial to add to the api a method to close the render window without destroying the environment.
That's not what happens (at least for classic_control and mujoco). Closing just closes the window.
@cfperez Can you post a small snippet explaining what you mean? That would be really helpful for us. Thanks!
Cheers! akaniamx
@akanimax Closing the cartpole environment just closes the viewer. https://github.com/openai/gym/blob/5c116fb3c91e872505300031d2bd60672b3a6e03/gym/envs/classic_control/cartpole.py#L140
In theory, you can create a new window, but requires explicitly setting the viewer attribute:
env.viewer = None
env.render()
I've filed #1107 to allow re-opening the window after closing.
This is fixed (see issue above). @pzhokhov feel free to close this.
env = gym.make("CarRacing-v0")
env.reset()
for i in range(1000):
env.render()
env.step(env.action_space.sample())
env.reset()
env.close()
This worked for me.
This issue is still on, but don't know why openai gym closed this issue.
same problem happens to me.
same problem here. I am using the GridWorld example
I have been fooling around with gym for a few days and boy is it frustrating. A minor nag is that I cant close any window that gets opened. For example:
import gym env = gym.make('CartPole-v0') highscore = 0 for i_episode in range(20): # run 20 episodes observation = env.reset() points = 0 # keep track of the reward each episode while True: # run until episode is done env.render() action = 1 if observation[2] > 0 else 0 # if angle if positive, move right. if angle is negative, move left observation, reward, done, info = env.step(action) points += reward if done: if points > highscore: # record high score highscore = points break
This runs fine but I am left with an open window each time. Like the other forum comments noted, this goes away when the jupyter notebook is closed. But it kinda stinks to have to open and close the whole thing each time.