Gym: ipython render window can't be closed

Created on 27 Apr 2016  Â·  21Comments  Â·  Source: openai/gym

If you attempt to create a notebook with the first CartPole example, the code runs but the rendered window cannot be closed:

gym-ipython

Neither the standard x, nor ctrl-c, nor terminating the kernel through the notebook UI cause the window to close. If you kill the parent ipython process from the cmd line, that will kill all the child windows as expected.

System: Ubuntu 14.04 64.

Pretty cool this works at all though!

Most helpful comment

You should be able to do env.render(close=True)

All 21 comments

You should be able to do env.render(close=True)

Thanks! That works. FYI my thought process was to 1. Try reset 2. look for top level methods like env.exit, env.stop, env.close etc.

Yeah, the render(close=...) method is definitely a compromise: we want to keep the env API as simple as possible, both for implementors and consumers of the interface. I didn't want to add a top-level close method, since it's hard to know exactly _what_ that'd mean (is the environment now permanently dead)? But if things get more complex, we could add a linked renderer object a la monitor.

I'll close this for now, and see how many other people get confused :).

I can't solve the problem with env.render(close=True) under macOS Sierra. If I try it, the renderized window just goes blank. Each time I call env.render(), a new window is created, and I can see all of them under mission control. Is there some way to close them?

I have this problem as well.

If I make two envs (both called env), I lose the handle for the first one, so I can't close the window with env.render.

Is there a solution in this case? (other than closing the interactive session)

I think this API is rather confusing indeed. I expect is to allow me to render the rgb view without opening a window but apparently that is not what it is doing. How can I get the desired behaviour?

Unfortunately the rendering engine (OpenGL) is part of the window system,
and it needs at least an invisible window to associate it with some display
hardware. Using a separate rendering engine for off-screen drawing is a
big project. Can you describe your use case to help us decide what we might
build?

On Tue, May 16, 2017 at 12:49 Ethan Luo notifications@github.com wrote:

I think this API is rather confusing indeed. I expect is to allow me to
render the rgb view without opening a window but apparently that is not
what it is doing. How can I get the desired behaviour?

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/openai/gym/issues/3#issuecomment-301895309, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AANZdEyC6JlO-kRfWbNBOG0gqZE2sc-jks5r6f3JgaJpZM4IRT_6
.

>

Trevor Blackwell [email protected] 650 776 7870

That is unfortunate. I do not really have a hard requirement for not displaying the window, but it is just that sometimes I do not need to see the window at all during training.

If you don't need the window at all, just don't call env.render().

@tlbtlbtlb I think I can't. In my experiment I am using the visual image data directly as feature input. However, I think there is no other API for me to obtain that other than using render?

Hi I just installed gym atari today. And ran the test code for atari:

`import gym

env = gym.make('SpaceInvaders-v0')

env.reset()

env.render()`

The Atar window pops open. however when I try to close with

env.render(close=True)

I get the error:
Traceback (most recent call last):
File "", line 1, in
TypeError: render() got an unexpected keyword argument 'close'

I am on ubuntu 16.04
gym version 0.10.3

@ahsteven I think close is now a top level method. Using env.close() at the end when you want to close the window works for Windows 10 on Python 3.5.0.

@cuongqn How do I close it after I interrupt the Kernel? env.close() is written at the end and will not work in case of Kernel interrupt. How do I close the window now?

The env.render(close=True) command does not work for me. I got the following error:

TypeError Traceback (most recent call last)
in ()
13 print("Total reward for episode: {}".format(episode_reward))
14 break
---> 15 random_agent(10)

in random_agent(num_episodes)
6
7 for t in range(1000):
----> 8 env.render(close=True)
9 action =env.action_space.sample()
10 observation, reward, done,info = env.step(action)

TypeError: render() got an unexpected keyword argument 'close'

In the new version of gym==0.9 you should use env.close() but it doesn't close the render window...
(neither before or after kernel interrupt)
I am using Ubuntu 16.04 and python 3.5

A workaround I found is to simply wrap the training/simulation loop in a try-finally block so that even if I exit the loop early, the window will close.

For example:

try:
    # training loop
finally:
    env.close()

This worked for me.

env.render(close=True)

This did not work for me in gym retro parallel learning
but what did work was self.env.render(close=True)
Thanks so much for the help
This has been a long issue that I could't fix but I finally did :)))))

env.render(close=True)
didn't work for me. but
env.render(mode='close')
work.

You can also try env.close(). That too works for me!

I am using jupyter-notebook
env.render(close=True)
didn't work, it says 'close' keyword not recognized.
env.close() worked better, but even then sometimes a black window remained.
I had to exit() to close in that case. I guess gym isn't made to run in ipython-like environments?

The version compatibility might be an issue. The best compatibility is found with python 3.6 and gym 0.15. Another hack is to use env.render() at the end of the for loop to close the window (in the same cell) and it works like charm!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pickittwice picture pickittwice  Â·  4Comments

Gawne picture Gawne  Â·  4Comments

david8373 picture david8373  Â·  4Comments

tylerlekang picture tylerlekang  Â·  3Comments

tornadomeet picture tornadomeet  Â·  4Comments