wsl support

This commit is contained in:
meelstorm
2025-08-28 16:30:29 +02:00
parent 07002dd875
commit bf13a5ea2d
4 changed files with 169 additions and 45 deletions

View File

@@ -1,21 +1,53 @@
namespace Hawkeye.VisionBuilder.Workflow.DataTransfer;
using Serilog;
namespace Hawkeye.VisionBuilder.Workflow.DataTransfer;
public class PythonModelProxyHTTP
{
private static bool _isInitialized = false;
private static UvicornScriptRunner _pythonScriptRunner;
private static DockerScriptRunner _pythonScriptRunner;
private static CSharpDataTransferHTTP _cSharpDataTransferHTTP;
static object _lock = new object();
public static void Initialize()
{
if (_isInitialized) return;
lock (_lock)
{
if (_isInitialized) return;
_isInitialized = true;
var workDirAbsPath = Path.GetFullPath(@"..\Data\Models");
_pythonScriptRunner = new UvicornScriptRunner(workDirAbsPath);
_cSharpDataTransferHTTP = new CSharpDataTransferHTTP();
var workDirAbsPath = Path.GetFullPath(@"..\Data\Models");
_pythonScriptRunner = new DockerScriptRunner(workDirAbsPath);
_pythonScriptRunner.Start();
Thread.Sleep(1000); // Wait for the server to start
_pythonScriptRunner.Start();
// Wait for the server to start by checking if port 8000 is open
while (true)
{
try
{
HttpClient http = new HttpClient();
// check if 404 occurs on localhost:8000
var response = http.GetAsync("http://127.0.0.1:8000/").Result;
if (response.StatusCode == System.Net.HttpStatusCode.NotFound ||
response.StatusCode == System.Net.HttpStatusCode.OK)
{
break; // Port is open
}
}
catch
{
Log.Debug("Waiting for port to open");
// Ignore exceptions and retry
}
Thread.Sleep(1000); // Wait before retrying
}
Thread.Sleep(2000);
_cSharpDataTransferHTTP = new CSharpDataTransferHTTP();
}
}
public static CSharpDataTransferHTTP GetInterface()