Privilege split 5/11: host kurgan.hw as a Windows service (pywin32)
- kurgan/hw/winservice.py: pywin32's ServiceFramework, hosted by the base interpreter's python.exe (PrepareToHostSingle + StartServiceCtrlDispatcher), not pythonservice.exe. The venv's python.exe is a redirector that starts the base interpreter as a child, and the service manager only talks to the process it started. Recorded as Decision 0002 in the vault. - Accepts stop and shutdown; both end the hardware loop, which leaves the case fans at 100% and hands the top fans back to the BIOS curve. An unexpected failure exits without reporting "stopped", so the recovery actions (set by setup.ps1: restart after 5 s, 10 s, 60 s) bring it back. - hw_service.py: the service's image, run as "<base python>" -I -S -B hw_service.py. It adds the repo and the venv's site-packages itself (pywin32's .pth bootstrap included), so the base interpreter's own packages never load and SYSTEM writes no .pyc into the repo. --check imports everything the service needs (setup.ps1 runs it first); started from a console it runs the service in the foreground. - requirements.txt: pywin32>=311 (312 has cp314 wheels). - Tests: 5 new (stop/shutdown, the run, failure exits, console fallback, and the bootstrap under the base interpreter in isolated mode). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7190db733f
commit
3e84ab1322
4 files changed
+190
No files matched your search
@@ -0,0 +1,25 @@
|
||||
"""Entry point of the "The Kurgan hardware" Windows service (KurganHw); see kurgan/hw/winservice.py.
|
||||
|
||||
The service manager runs it with the base interpreter (setup.ps1 installs it):
|
||||
|
||||
"<base Python>\\python.exe" -I -S -B "C:\\Dev\\the_kurgan\\hw_service.py"
|
||||
|
||||
-I: isolated (no PYTHON* variables, no user site-packages, no current folder on the path);
|
||||
-S: no automatic site-packages; -B: no .pyc files written into the repo by SYSTEM. This file
|
||||
adds the repo and its .venv's packages, so the base interpreter's own packages are never loaded.
|
||||
|
||||
... hw_service.py --check can the service start? (setup.ps1 runs this before installing)
|
||||
... hw_service.py [-v] run it in a console instead (elevated, with the service stopped)
|
||||
"""
|
||||
|
||||
import os
|
||||
import site
|
||||
import sys
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
sys.path.insert(0, HERE)
|
||||
site.addsitedir(os.path.join(HERE, ".venv", "Lib", "site-packages")) # runs pywin32's .pth bootstrap
|
||||
|
||||
from kurgan.hw.winservice import main # noqa: E402
|
||||
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user