Separate persistent user data from application code (data/work_tracker.db, data/uploads, data/storage) with idempotent legacy migration and SQLite integrity checks. Add offline packaging scripts for a Windows x11 x64 portable ZIP (embeddable Python, Start/Stop/Backup.bat). Fix launcher: no multiline python -c in BAT and no os.dup2 — uvicorn runs detached with wvt.log; health wait and busy-port diagnostics included.
2.7 KiB
Fix portable Start.bat — OSError(9) / lost sys.stderr
Root cause
-
User failure (
OSError(9, 'Неверный дескриптор'),lost sys.stderr)run_server.pycalledos.dup2(log.fileno(), 1/2)while the process was started withstart /b. The inherited Windows stdio HANDLEs can already be invalid;dup2fixes CRT fds but Python/CPython still write through the oldsys.stderrobject / Windows handle →OSError(9)andlost sys.stderr. Uvicorn then dies →startup.logshowsTIMEOUT/health timeout. -
Automation hang (reproduced in smoke): a child started with
start /boros.spawnvinherits the BAT’s stdout pipe; parentcmd /cwaits for EOF until the server exits.os.spawnvalso does not quote spaces in paths (финал 179…\WorkVolumeTrackerbroke argv).
Fix
- No
os.dup2in the server process. Start.bat→python scripts\start_server.py(synchronous, short-lived).start_server.pyspawnsrun_server.pywithsubprocess.Popenlist argv (quotes spaces/Cyrillic) +DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP,stdin=NUL,stdout/stderr=wvt.logfile handles.run_server.pyonly replaces Python-levelsys.stdout/stderr(never OS fds); writeswvt.pid; full traceback towvt-crash.log.wait_health.pyuses raw sockets (no urllib).Start.bat:startup.logSTEPs, diagnostics (diagnose_start.py) on timeout,WVT_NO_PAUSE/WVT_NO_BROWSERfor automation;pauseon errors in interactive use.
Changed files
packaging/Start.bat, packaging/scripts/run_server.py, packaging/scripts/start_server.py, packaging/scripts/wait_health.py, packaging/scripts/diagnose_start.py (already present), packaging/build_portable.py (ships scripts, BAT as UTF-8 BOM+CRLF).
Host repo user data, legacy dirs, QA, POST-E2E/BUG-UI, KS-6a — untouched. Staging empty. No commit/push.
New ZIP
C:\MVP-project\_portable_build\WorkVolumeTracker-portable-win11-x64.zip
21 853 833 bytes · 2026-10-20
Tests (clean extract, path with spaces + Cyrillic)
| Check | Result |
|---|---|
| Start.bat rc=0 (~5–12 s) | PASS |
/health 200, /projects/ 200 |
PASS |
wvt.log has Uvicorn running |
PASS |
wvt.log no OSError / lost sys.stderr |
PASS |
wvt-crash.log missing (no crash) |
PASS |
| Stop.bat, port closed | PASS |
| Second Start.bat after stop | PASS |
startup.log STEPs + READY |
PASS |
Missing python.exe / busy port (earlier) |
PASS |
Notes
save_pid.pymay still printPID_NOT_FOUND;run_server.pywritesdata\wvt.pid(used by Stop).- Browser open uses
start "" /band can be skipped viaWVT_NO_BROWSER=1.