浏览代码

Merge pull request #2580 from Unity-Technologies/develop-removeUnitySDKlog

Remove UnitySDK.log file
/develop-gpu-test
GitHub 5 年前
当前提交
11e13518
共有 2 个文件被更改,包括 2 次插入57 次删除
  1. 30
      UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
  2. 29
      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.

29
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):

正在加载...
取消
保存