lifeline.popen ties every engine, image encoder, MCP server and sd-cli to the server that started them (kill-on-close job on Windows, PR_SET_PDEATHSIG from one anchor thread on Linux, a pipe watcher elsewhere). Engines and encoders get their own process group so Ctrl+C, a closing terminal and a console Break reach the server only, which stops the engine the clean way (STOP, QUIT, wait 20 s, terminate 5 s, kill). SIGHUP, SIGBREAK and the Windows console close/logoff/shutdown events take Ctrl+C's path; the handlers are installed before the model loads and the browser launch no longer holds the main thread (#1872). The owner guard escalates SIGTERM to SIGKILL after a grace period. strata_control/procs.py records every launch and finds leftovers; the next engine start, runtime start, runtime stop and the new runtime cleanup end them after re-checking identity. runtime start --die-with-pid for app-owned instances. tests/terminal/lifecycle_matrix.py is the close-path matrix.
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""Closing always ends the engine: the close-path matrix (tests/terminal/lifecycle_matrix.py) with the fake engine.
|
|
|
|
Each case starts `strata serve` or `strata runtime start` with an engine package whose entry point is a script,
|
|
ends it one way, and asserts that no process of the tree is left, the port is free and the runtime lease can be taken.
|
|
The cases that need a real console window on Windows run when STRATA_MATRIX_CONSOLE=1 (they open a minimised
|
|
console); everything else runs everywhere the platform has the mechanism.
|
|
"""
|
|
import os
|
|
import unittest
|
|
|
|
from tests.terminal import lifecycle_matrix as matrix
|
|
|
|
CONSOLE = {"serve-ctrl-c", "serve-console-close"}
|
|
|
|
|
|
@unittest.skipUnless(os.name in ("posix", "nt"), "no qualified owner transport on this platform")
|
|
class LifecycleMatrix(unittest.TestCase):
|
|
pass
|
|
|
|
|
|
def make(name):
|
|
def test(self):
|
|
if matrix.WINDOWS and name in CONSOLE and not os.environ.get("STRATA_MATRIX_CONSOLE"):
|
|
self.skipTest("needs a console window; set STRATA_MATRIX_CONSOLE=1")
|
|
result = matrix.run([name])[0]
|
|
self.assertTrue(result["ok"], result.get("problems"))
|
|
return test
|
|
|
|
|
|
for _name in matrix.SCENARIOS:
|
|
if matrix.applicable(_name):
|
|
setattr(LifecycleMatrix, "test_" + _name.replace("-", "_"), make(_name))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|