hardmaru / slimevolleygym

A simple OpenAI Gym environment for single and multi-agent reinforcement learning
Apache License 2.0
725 stars 111 forks source link

env.close doesn't close the render window #6

Closed bionicles closed 4 years ago

bionicles commented 4 years ago

when you run this code:

# tests/test_envs.py
import gym

SLIME_VOLLEY_NAMES = ['SlimeVolley-v0','SlimeVolleyPixel-v0','SlimeVolleyNoFrameskip-v0']

def check_env(name):
    print('check env', name)
    env = gym.make(name)
    o = env.reset()
    o,r,d,i = env.step(env.action_space.sample())
    try:
        env.render()
    except Exception as e:
        print(name, 'doesnt implement render   <-----')
    env.close()
    try:
        env.render(close=True)
    except Exception as e:
        print(name, 'doesnt support close=True <-----')
        print(e)

def test_envs():
    [check_env(name) for name in SLIME_VOLLEY_NAMES]
pytest -s tests/test_envs.py

the windows don't seem to close when we call env.close -- they stay open until the whole script is done.

How do you close the render window, or is this test code screwed up?

hardmaru commented 4 years ago

Hi @bionicles,

Thanks for the test. It doesn't seem to be a prob on my machine. I ran your test, and here is my output:

=============================================================================== test session starts ===============================================================================
platform darwin -- Python 3.6.1, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
rootdir: /Users/hadavid/devel/slimevolleygym, inifile:
plugins: cov-2.5.1
collected 1 items

tests/test_envs.py check env SlimeVolley-v0
/Users/hadavid/anaconda/lib/python3.6/site-packages/gym/logger.py:30: UserWarning: WARN: gym.spaces.Box autodetected dtype as <class 'numpy.float32'>. Please provide explicit dtype.
  warnings.warn(colorize('%s: %s'%('WARN', msg % args), 'yellow'))
check env SlimeVolleyPixel-v0
check env SlimeVolleyNoFrameskip-v0
.

============================================================================ 1 passed in 1.01 seconds =============================================================================

My windows also close properly.

Here are the list of relevant packages I use:

Python 3.6.1 :: Anaconda 4.4.0 (x86_64)
gym                                0.11.0
pyglet                             1.5.0

I while back I noticed that their viewer didn't close the window properly, and at the time I submitted a PR to gym that fixed it and it was merged:

https://github.com/openai/gym/pull/1912

hardmaru commented 4 years ago

But I'll merge the PR you submitted anyways since I think it'll help close all the windows at the right time, thanks.