Files
cyclop/run_python_with_restart.ps1
T
2024-08-20 13:11:24 -05:00

38 lines
905 B
PowerShell

param(
[Parameter(Mandatory=$true)]
[string]$PythonFile
)
function Run-PythonScript {
param($ScriptPath)
$process = Start-Process -FilePath "python" -ArgumentList $ScriptPath -PassThru -Wait -NoNewWindow
return $process.ExitCode
}
function Git-Pull {
git pull
return $LASTEXITCODE -eq 0
}
$waitTime = 15
while ($true) {
$exitCode = Run-PythonScript -ScriptPath $PythonFile
if (Test-Path -Path ".\.doreboot") {
Write-Host "Special filename detected. Attempting git pull..."
if (Git-Pull) {
Write-Host "Git pull successful. Restarting Python script..."
$waitTime = 15
continue
} else {
Write-Host "Git pull failed. Waiting $waitTime seconds before next attempt..."
}
} else {
exit 1
}
Start-Sleep -Seconds $waitTime
$waitTime *= 2
}