浏览代码

Removed writing to UnitySDK.log from Academy/Changed UnityTimeOutException to no longer read from UnitySDK.log

/develop-gpu-test
Andrew Cohen 5 年前
当前提交
86c598bb
共有 2 个文件被更改,包括 3 次插入58 次删除
  1. 30
      UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
  2. 31
      ml-agents-envs/mlagents/envs/exception.py

30
UnitySDK/Assets/ML-Agents/Scripts/Academy.cs


/// Pointer to the batcher currently in use by the Academy.
Batcher m_BrainBatcher;
/// Used to write error messages.
StreamWriter m_LogWriter;
/// The path to where the log should be written.
string m_LogPath;
// Flag used to keep track of the first time the Academy is reset.
bool m_FirstAcademyReset;

var pythonParameters = m_BrainBatcher.SendAcademyParameters(academyParameters);
Random.InitState(pythonParameters.Seed);
Application.logMessageReceived += HandleLog;
m_LogPath = Path.GetFullPath(".") + "/UnitySDK.log";
using (var fs = File.Open(m_LogPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
m_LogWriter = new StreamWriter(fs);
m_LogWriter.WriteLine(System.DateTime.Now.ToString());
m_LogWriter.WriteLine(" ");
m_LogWriter.Close();
}
}
// If a communicator is enabled/provided, then we assume we are in

customResetParameters = newResetParameters.CustomResetParameters;
}
}
void HandleLog(string logString, string stackTrace, LogType type)
{
using (var fs = File.Open(m_LogPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
m_LogWriter = new StreamWriter(fs);
m_LogWriter.WriteLine(type.ToString());
m_LogWriter.WriteLine(logString);
m_LogWriter.WriteLine(stackTrace);
m_LogWriter.Close();
}
}
/// <summary>
/// Configures the environment settings depending on the training/inference
/// mode and the corresponding parameters passed in the Editor.

31
ml-agents-envs/mlagents/envs/exception.py


"""
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
unity_error = "\n"
for line in f:
line = line.strip()
if (line == "Exception") or (line == "Error"):
printing = True
unity_error += "----------------------\n"
if line == "":
printing = False
if printing:
unity_error += line + "\n"
logger.info(unity_error)
logger.error(
"An error might have occured in the environment. "
"You can check the logfile for more information at {}".format(
log_file_path
)
)
except Exception:
logger.error(
"An error might have occured in the environment. "
"No UnitySDK.log file could be found."
)
super(UnityTimeOutException, self).__init__(message)
pass
class UnityWorkerInUseException(UnityException):

正在加载...
取消
保存