浏览代码

made the UnityTimeOutException that reads into the logfile when available

/tag-0.2.0
vincentpierre 7 年前
当前提交
34b6e786
共有 2 个文件被更改,包括 43 次插入25 次删除
  1. 42
      python/unityagents/environment.py
  2. 26
      python/unityagents/exception.py

42
python/unityagents/environment.py


import struct
from .brain import BrainInfo, BrainParameters
from .exception import UnityEnvironmentException, UnityActionException
from .exception import UnityEnvironmentException, UnityActionException, UnityTimeOutException
from .curriculum import Curriculum
from PIL import Image

try:
self._socket.listen(1)
self._conn, _ = self._socket.accept()
# self._conn.setblocking(1)
self._conn.settimeout(5)
self._conn.settimeout(10)
raise UnityEnvironmentException(
raise UnityTimeOutException(
"The Unity environment took too long to respond. Make sure {} does not need user interaction to "
"launch and that the Academy and the external Brain(s) are attached to objects in the Scene."
.format(str(file_name)))

for k in self._resetParameters])) + '\n' + \
'\n'.join([str(self._brains[b]) for b in self._brains])
def _recv_bytes(self):
try:
s = self._conn.recv(self._buffer_size)

s += self._conn.recv(self._buffer_size)
except socket.timeout as e:
if not os.path.isfile(self._log_path):
raise UnityEnvironmentException("The environment took too long to respond. "
"No unity-environment.log file could be found.")
else:
print("An error may have occured in the environment. "
"You can check the logfile for more information at {}".format(self._log_path))
with open(self._log_path, "r") as f:
printing= False
for l in f:
l=l.strip()
if (l == 'Exception') or (l=='Error'):
printing = True
print('----------------------')
if (l == ''):
printing = False
if printing:
print(l)
raise UnityEnvironmentException("The environment took too long to respond.")
raise UnityTimeOutException("The environment took too long to respond.", self._log_path)
return s
def _get_state_image(self, bw):

', '.join([str(x) + ' -> ' + str(config[x]) for x in config])))
if self._loaded:
self._conn.send(b"RESET")
self._conn.recv(self._buffer_size)
try:
self._conn.recv(self._buffer_size)
except socket.timeout as e:
raise UnityTimeOutException("The environment took too long to respond.", self._log_path)
self._conn.send(json.dumps({"train_model": train_mode, "parameters": config}).encode('utf-8'))
for k in config:
if (k in self._resetParameters) and (isinstance(config[k], (int, float))):

self._data[b] = BrainInfo(observations, states, memories, rewards, agents, dones, actions)
self._global_done = self._conn.recv(self._buffer_size).decode('utf-8') == 'True'
try:
self._global_done = self._conn.recv(self._buffer_size).decode('utf-8') == 'True'
except socket.timeout as e:
raise UnityTimeOutException("The environment took too long to respond.", self._log_path)
return self._data

:param memory: a dictionary of lists of of memories.
:param value: a dictionary of lists of of value estimates.
"""
self._conn.recv(self._buffer_size)
try:
self._conn.recv(self._buffer_size)
except socket.timeout as e:
raise UnityTimeOutException("The environment took too long to respond.", self._log_path)
action_message = {"action": action, "memory": memory, "value": value}
self._conn.send(json.dumps(action_message).encode('utf-8'))

26
python/unityagents/exception.py


Related to errors with sending actions.
"""
pass
class UnityTimeOutException(Exception):
"""
Related to errors with communication timeouts.
"""
def __init__(self, message, log_file_path = None):
if log_file_path is not None:
try:
with open(log_file_path, "r") as f:
printing = False
for l in f:
l=l.strip()
if (l == 'Exception') or (l=='Error'):
printing = True
print('----------------------')
if (l == ''):
printing = False
if printing:
print(l)
print("An error might have occured in the environment. "
"You can check the logfile for more information at {}".format(log_file_path))
except:
print("An error might have occured in the environment. "
"No unity-environment.log file could be found.")
super(UnityTimeOutException, self).__init__(message)
正在加载...
取消
保存