Ejemplo n.º 1
0
 private static void ProcessOutputLine(string type, string line, PhotoProcessResult status)
 {
     if (string.IsNullOrWhiteSpace(line))
     {
         return;
     }
     Startup.EphemeralLog($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {type}: {line}");
     if (type == "stdout")
     {
         if (line.Contains("CUDA out of memory", StringComparison.InvariantCultureIgnoreCase) ||
             line.Contains("not enough memory", StringComparison.InvariantCultureIgnoreCase))
         {
             status.ErrorCount++;
             status.Errors.Add(line);
         }
     }
     else if (type == "stderr")
     {
         if (line.Contains("warning", StringComparison.InvariantCultureIgnoreCase) ||
             line.Contains("nn.Upsample", StringComparison.InvariantCultureIgnoreCase))
         {
             // not an error, process wrongly logging success status to stderr
         }
         else
         {
             status.ErrorCount++;
             status.Errors.Add(line);
         }
     }
 }
Ejemplo n.º 2
0
        private PhotoProcessResult ExecuteImpl(string traceId, string gpu, bool scratched)
        {
            var output  = new StringBuilder();
            var status  = new PhotoProcessResult();
            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = @"cmd.exe",
                    RedirectStandardInput  = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                },
                EnableRaisingEvents = true
            };

            process.ErrorDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    ProcessOutputLine("stderr", e.Data, status);
                }
            });
            process.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    ProcessOutputLine("stdout", e.Data, status);
                }
            });
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
            var inputFolder  = Path.Combine(InputFolderRoot, traceId);
            var outputFolder = Path.Combine(OutputFolderRoot, traceId);

            Directory.CreateDirectory(outputFolder);
            if (string.IsNullOrEmpty(gpu))
            {
                gpu = GpuParam;
            }
            var command = @$ "python run.py --input_folder " "{inputFolder}" " --output_folder " "{outputFolder}" " --GPU {gpu} {(scratched ? "-- with_scratch " : " ")}";

            // TODO: param for sctrath detection
            Startup.EphemeralLog($"Will execute: {command}", false);

            using (var sw = process.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine(Anaconda_Activate_Script);

                    sw.WriteLine(@$ "CD " "{AppDir}" "");
                    sw.WriteLine(command);
                    sw.WriteLine("conda deactivate");
                }
            }
            WaitOrKill(process, 30, command);
            status.OutputFolder = Path.Combine(outputFolder, "final_output");
            status.ExitCode     = process.ExitCode;
            return(status);
        }