18 using System.Threading;
30 private const string _collapseMessage =
"Unhandled exception breaking past controls and causing collapse of algorithm node. This is likely a memory leak of an external dependency or the underlying OS terminating the LEAN engine.";
38 AppDomain.CurrentDomain.AssemblyLoad += (sender, e) =>
40 if (e.LoadedAssembly.FullName.ToLowerInvariant().Contains(
"python"))
42 Log.
Trace($
"Python for .NET Assembly: {e.LoadedAssembly.GetName()}");
47 static void Main(
string[] args)
51 Console.OutputEncoding = System.Text.Encoding.UTF8;
61 Thread.CurrentThread.Name =
"Algorithm Analysis Thread";
67 job = leanEngineSystemHandlers.
JobQueue.NextJob(out var assemblyPath);
73 const string jobNullMessage =
"Engine.Main(): Sorry we could not process this algorithm request.";
75 throw new ArgumentException(jobNullMessage);
89 leanEngineSystemHandlers.
Notify.SetAuthentication(job);
91 leanEngineSystemHandlers.
JobQueue.AcknowledgeJob(job);
98 Console.CancelKeyPress +=
new ConsoleCancelEventHandler(ExitKeyPress);
103 leanEngineSystemHandlers.
LeanManager.Initialize(leanEngineSystemHandlers, leanEngineAlgorithmHandlers, job, algorithmManager);
118 public static void ExitKeyPress(
object sender, ConsoleCancelEventArgs args)
125 Log.
Trace(
"Program.ExitKeyPress(): Lean instance has been cancelled, shutting down safely now");
128 public static void Exit(
int exitCode)
131 leanEngineSystemHandlers.
JobQueue.AcknowledgeJob(job);
135 leanEngineSystemHandlers.DisposeSafely();
136 leanEngineAlgorithmHandlers.DisposeSafely();
142 Log.
Trace(
"Program.Main(): Exiting Lean...");
143 Environment.Exit(exitCode);