mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-02 06:16:32 +00:00
monitor.py: Still write manifest if close errors
Before, on a headless server I was losing manifests with: NullFunctionError: Attempt to call an undefined function glIsFramebuffer, check for bool(glIsFramebuffer) before calling (when closing Ant-v0)
This commit is contained in:
@@ -155,14 +155,14 @@ class Monitor(object):
|
||||
# during video recording.
|
||||
try:
|
||||
self.env.render(close=True)
|
||||
except Exception:
|
||||
type, value, traceback = sys.exc_info()
|
||||
except Exception as e:
|
||||
if self.env.spec:
|
||||
key = self.env.spec.id
|
||||
else:
|
||||
key = self.env
|
||||
# This likely indicates unsupported kwargs
|
||||
six.reraise(type, '{} (when closing {})'.format(value, key), traceback)
|
||||
# We don't want to avoid writing the manifest simply
|
||||
# because we couldn't close the renderer.
|
||||
logger.warn('Could not close renderer for %s: %s'.format(key, e))
|
||||
|
||||
# Give it a very distiguished name, since we need to pick it
|
||||
# up from the filesystem later.
|
||||
|
36
gym/monitoring/tests/test_monitor.py
Normal file
36
gym/monitoring/tests/test_monitor.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import contextlib
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import gym
|
||||
from gym.monitoring import monitor
|
||||
|
||||
class FakeEnv(gym.Env):
|
||||
def _render(self, close=True):
|
||||
raise RuntimeError('Raising')
|
||||
|
||||
@contextlib.contextmanager
|
||||
def tempdir():
|
||||
temp = tempfile.mkdtemp()
|
||||
yield temp
|
||||
shutil.rmtree(temp)
|
||||
|
||||
def test_monitor_filename():
|
||||
with tempdir() as temp:
|
||||
env = gym.make('Acrobot-v0')
|
||||
env.monitor.start(temp)
|
||||
env.monitor.close()
|
||||
|
||||
manifests = glob.glob(os.path.join(temp, '*.manifest.*'))
|
||||
assert len(manifests) == 1
|
||||
|
||||
def test_close_monitor():
|
||||
with tempdir() as temp:
|
||||
env = FakeEnv()
|
||||
env.monitor.start(temp)
|
||||
env.monitor.close()
|
||||
|
||||
manifests = monitor.detect_training_manifests(temp)
|
||||
assert len(manifests) == 1
|
Reference in New Issue
Block a user