Allow environment to create a new monitor after closing

This commit is contained in:
Greg Brockman
2016-05-15 16:43:53 -07:00
parent 1d41486480
commit 064f7377d9
2 changed files with 17 additions and 0 deletions

View File

@@ -191,6 +191,8 @@ class Monitor(object):
logger.error('Could not close renderer for %s: %s', key, e)
self.enabled = False
# Remove the env's pointer to this monitor
del self.env._monitor
# Stop tracking this for autoclose
del monitors[self.monitor_id]

View File

@@ -45,3 +45,18 @@ def test_video_callable():
pass
else:
assert False
def test_env_reuse():
with tempdir() as temp:
env = gym.make('CartPole-v0')
env.monitor.start(temp)
env.monitor.close()
env.monitor.start(temp, force=True)
env.reset()
env.step(env.action_space.sample())
env.step(env.action_space.sample())
env.monitor.close()
results = monitor.load_results(temp)
assert results['episode_lengths'] == [2], 'Results: {}'.format(results)