mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-09-01 10:27:43 +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)
|
logger.error('Could not close renderer for %s: %s', key, e)
|
||||||
|
|
||||||
self.enabled = False
|
self.enabled = False
|
||||||
|
# Remove the env's pointer to this monitor
|
||||||
|
del self.env._monitor
|
||||||
# Stop tracking this for autoclose
|
# Stop tracking this for autoclose
|
||||||
del monitors[self.monitor_id]
|
del monitors[self.monitor_id]
|
||||||
|
|
||||||
|
@@ -45,3 +45,18 @@ def test_video_callable():
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
assert False
|
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