mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-31 18:12:53 +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.
|
# during video recording.
|
||||||
try:
|
try:
|
||||||
self.env.render(close=True)
|
self.env.render(close=True)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
type, value, traceback = sys.exc_info()
|
|
||||||
if self.env.spec:
|
if self.env.spec:
|
||||||
key = self.env.spec.id
|
key = self.env.spec.id
|
||||||
else:
|
else:
|
||||||
key = self.env
|
key = self.env
|
||||||
# This likely indicates unsupported kwargs
|
# We don't want to avoid writing the manifest simply
|
||||||
six.reraise(type, '{} (when closing {})'.format(value, key), traceback)
|
# 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
|
# Give it a very distiguished name, since we need to pick it
|
||||||
# up from the filesystem later.
|
# 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