<commit_before>using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using Debug = UnityEngine.Debug;


namespace GitHub.Unity
{
	class ProcessTask : ITask
	{
		const int ExitMonitorSleep = 10;


		[MenuItem("Assets/GitHub/Process Test")]
		static void Test()
		{
			EditorApplication.delayCall += () => Tasks.Add(new ProcessTask());
		}


		public bool Blocking { get { return true; } }
		public float Progress { get; protected set; }
		public bool Done { get; protected set; }
		public bool Queued { get { return true; } }
		public bool Critical { get { return true; } }
		public bool Cached { get { return true; } }
		public Action<ITask> OnBegin { get; set; }
		public Action<ITask> OnEnd { get; set; }
		public string Label { get { return "Process task"; } }


		Process process;


		public static ProcessTask Parse(IDictionary<string, object> data)
		// Try to reattach to the process. Assume that we're done if that fails.
		{
			Process resumedProcess;

			try
			{
				resumedProcess = Process.GetProcessById((int)(Int64)data[Tasks.ProcessKey]);
			}
			catch(Exception)
			{
				resumedProcess = null;
			}

			return new ProcessTask()
			{
				process = resumedProcess,
				Done = resumedProcess == null,
				Progress = resumedProcess == null ? 1f : 0f
			};
		}


		public void Run()
		{
			Debug.LogFormat("{0} {1}", Label, process == null ? "start" : "reconnect");

			Done = false;
			Progress = 0.0f;

			if(OnBegin != null)
			{
				OnBegin(this);
			}

			if(process == null)
			{
				process = Process.Start("sleep", "20");
			}

			// NOTE: WaitForExit is too low level here. Won't be properly interrupted by thread abort.
			while(!process.HasExited)
			{
				Thread.Sleep(ExitMonitorSleep);
			}

			Progress = 1.0f;
			Done = true;

			Debug.LogFormat("{0} end", Label);

			if(OnEnd != null)
			{
				OnEnd(this);
			}
		}


		public void Abort()
		{
			Debug.LogFormat("Aborting {0}", Label);

			process.Kill();

			Done = true;
		}


		public void Disconnect()
		{
			Debug.LogFormat("Disconnect {0}", Label);<commit_msg>Cleaner Abort for ProcessTask.<commit_after>using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using Debug = UnityEngine.Debug;


namespace GitHub.Unity
{
	class ProcessTask : ITask
	{
		const int ExitMonitorSleep = 10;


		[MenuItem("Assets/GitHub/Process Test")]
		static void Test()
		{
			EditorApplication.delayCall += () => Tasks.Add(new ProcessTask());
		}


		public bool Blocking { get { return true; } }
		public float Progress { get; protected set; }
		public bool Done { get; protected set; }
		public bool Queued { get { return true; } }
		public bool Critical { get { return true; } }
		public bool Cached { get { return true; } }
		public Action<ITask> OnBegin { get; set; }
		public Action<ITask> OnEnd { get; set; }
		public string Label { get { return "Process task"; } }


		Process process;


		public static ProcessTask Parse(IDictionary<string, object> data)
		// Try to reattach to the process. Assume that we're done if that fails.
		{
			Process resumedProcess;

			try
			{
				resumedProcess = Process.GetProcessById((int)(Int64)data[Tasks.ProcessKey]);
			}
			catch(Exception)
			{
				resumedProcess = null;
			}

			return new ProcessTask()
			{
				process = resumedProcess,
				Done = resumedProcess == null,
				Progress = resumedProcess == null ? 1f : 0f
			};
		}


		public void Run()
		{
			Debug.LogFormat("{0} {1}", Label, process == null ? "start" : "reconnect");

			Done = false;
			Progress = 0.0f;

			if(OnBegin != null)
			{
				OnBegin(this);
			}

			if(process == null)
			{
				process = Process.Start("sleep", "20");
			}

			// NOTE: WaitForExit is too low level here. Won't be properly interrupted by thread abort.
			while(!process.HasExited)
			{
				Thread.Sleep(ExitMonitorSleep);
			}

			Progress = 1.0f;
			Done = true;

			Debug.LogFormat("{0} end", Label);

			if(OnEnd != null)
			{
				OnEnd(this);
			}
		}


		public void Abort()
		{
			Debug.LogFormat("Aborting {0}", Label);

			try
			{
				process.Kill();
			}
			catch(Exception)
			{}

			Done = true;

			if(OnEnd != null)
			{
				OnEnd(this);
			}
		}


		public void Disconnect()
		{
			Debug.LogFormat("Disconnect {0}", Label);
{'fraction_non_alphanumeric': 0.1262488646684832, 'fraction_numerical': 0.007720254314259764, 'mean_word_length': 3.019160583941606, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3225852', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1408, 'n_words': 391}