From f0c70e2e1f47e34f2fd303ff241a878b9a9e37a4 Mon Sep 17 00:00:00 2001 From: Codex Date: Wed, 1 Jul 2026 13:43:41 +0300 Subject: [PATCH] Run Windows training agent without console --- tools/install_windows_training_agent.ps1 | 11 ++++++++++- tools/windows_training_agent.py | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/install_windows_training_agent.ps1 b/tools/install_windows_training_agent.ps1 index b67a5b6..5e83f0c 100644 --- a/tools/install_windows_training_agent.ps1 +++ b/tools/install_windows_training_agent.ps1 @@ -40,6 +40,15 @@ function Resolve-Python { throw "Python was not found. Create .venv or install Python 3.12." } +function Resolve-WindowlessPython { + $python = Resolve-Python + $pythonw = Join-Path (Split-Path -Parent $python) "pythonw.exe" + if (Test-Path $pythonw) { + return $pythonw + } + return $python +} + if ($ApiAuth) { [Environment]::SetEnvironmentVariable("TRADEBOT_API_AUTH", $ApiAuth, "User") $env:TRADEBOT_API_AUTH = $ApiAuth @@ -59,7 +68,7 @@ if (-not $KeepLegacyRetrainer) { } } -$python = Resolve-Python +$python = Resolve-WindowlessPython $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name $arguments = @( "-u", diff --git a/tools/windows_training_agent.py b/tools/windows_training_agent.py index 6290c88..f8301d1 100644 --- a/tools/windows_training_agent.py +++ b/tools/windows_training_agent.py @@ -296,7 +296,11 @@ def log(path: Path, message: str) -> None: path.parent.mkdir(parents=True, exist_ok=True) stamp = datetime.now().astimezone().isoformat(timespec="seconds") line = f"[{stamp}] {message}" - print(line, flush=True) + if sys.stdout is not None: + try: + print(line, flush=True) + except OSError: + pass with path.open("a", encoding="utf-8") as handle: handle.write(line + "\n")