浏览代码

Fix parallel writes to UnitySDK.log on Windows

When using the SubprocessUnityEnvironment, parallel writes are
made to UnitySDK.log. This causes file access violation issues
in Windows/C#. This change modifies the access and sharing mode
for our writes to UnitySDK.log to fix the issue.
/develop-generalizationTraining-TrainerController
Jonathan Harper 6 年前
当前提交
18bedf6a
共有 1 个文件被更改,包括 15 次插入9 次删除
  1. 24
      UnitySDK/Assets/ML-Agents/Scripts/Academy.cs

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


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

void HandleLog(string logString, string stackTrace, LogType type)
{
logWriter = new StreamWriter(logPath, true);
logWriter.WriteLine(type.ToString());
logWriter.WriteLine(logString);
logWriter.WriteLine(stackTrace);
logWriter.Close();
using (var fs = File.Open(logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
logWriter = new StreamWriter(fs);
logWriter.WriteLine(type.ToString());
logWriter.WriteLine(logString);
logWriter.WriteLine(stackTrace);
logWriter.Close();
}
}
/// <summary>

正在加载...
取消
保存