mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-31 10:09:53 +00:00
Allow environment to create a new monitor after closing
This commit is contained in:
@@ -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]
|
||||
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user