$ErrorActionPreference = "Stop" $apiDir = Split-Path -Parent $MyInvocation.MyCommand.Path $python = "C:\Users\alfia\anaconda3\envs\tf_gpu39\python.exe" $port = 8000 if (-not (Test-Path $python)) { throw "Python environment tf_gpu39 tidak ditemukan: $python" } Write-Host "Menghentikan proses backend PrediksiHargaCabe..." $projectProcesses = Get-CimInstance Win32_Process | Where-Object { $_.ProcessId -ne $PID -and $_.CommandLine -and $_.CommandLine -match [regex]::Escape($apiDir) -and $_.CommandLine -match "main\.py|flask|waitress|gunicorn" } foreach ($process in $projectProcesses) { Write-Host " Stop PID $($process.ProcessId)" Stop-Process -Id $process.ProcessId -Force -ErrorAction SilentlyContinue } $portConnections = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue foreach ($connection in $portConnections) { if ($connection.OwningProcess -and $connection.OwningProcess -ne $PID) { Write-Host " Membebaskan port $port dari PID $($connection.OwningProcess)" Stop-Process -Id $connection.OwningProcess -Force -ErrorAction SilentlyContinue } } Start-Sleep -Seconds 1 Set-Location $apiDir $env:FLASK_DEBUG = "1" $env:PYTHONUNBUFFERED = "1" Write-Host "Menjalankan backend dengan auto-reloader dari $apiDir" Write-Host "Perubahan file Python akan dimuat otomatis. Tekan Ctrl+C untuk berhenti." & $python "main.py"