From 9a0746fa8b75569ebd0a4865a5bf2669f2fc1eca Mon Sep 17 00:00:00 2001 From: Derek Holloway Date: Thu, 26 Feb 2026 21:43:28 -0800 Subject: [PATCH] Seperate out the PullAI on the front end --- WebServer/Controllers/PythonInterop.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/WebServer/Controllers/PythonInterop.cs b/WebServer/Controllers/PythonInterop.cs index dfe303b4..406ccd49 100644 --- a/WebServer/Controllers/PythonInterop.cs +++ b/WebServer/Controllers/PythonInterop.cs @@ -1,5 +1,4 @@ using Python.Runtime; -using System.Text.Json; namespace PythonInterop { @@ -22,19 +21,27 @@ namespace PythonInterop { PythonEngine.BeginAllowThreads(); } - // This is thread blocking, runs on the main thread, and takes multiple minutes so probabaly need to run on a background thread at some point + public void PullAI() { + using (Py.GIL()) { + dynamic datapuller = Py.Import("datapuller"); + using (datapuller.pull()){ } + } + } + public void TrainAI() { using (Py.GIL()) { - dynamic datapuller = Py.Import("ai-trainer"); - dynamic result = datapuller.TrainAI(); + dynamic trainer = Py.Import("ai-trainer"); + using (trainer.TrainAI()){ } } } public int PredictAI(string StockSymbol) { using (Py.GIL()) { - dynamic main = Py.Import("ai-predictor"); - int result = main.Predict(StockSymbol); - return result; + dynamic predictor = Py.Import("ai-predictor"); + using (dynamic x = predictor.Predict(StockSymbol)) { + int result = (int)x; + return result; + } } }