import os import subprocess import sys import tempfile import time from pathlib import Path from unittest import TestCase class ParentExitTest(TestCase): def test_backend_shuts_down_when_ui_owner_exits(self): with tempfile.TemporaryDirectory() as directory: path=Path(directory)/'service.sock' source='''import os,subprocess,sys,time p=subprocess.Popen([sys.executable,'-m','station.control_service','--socket',sys.argv[1],'--offline','--parent-pid',str(os.getpid())],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL) print(p.pid,flush=True) end=time.monotonic()+8 while not os.path.exists(sys.argv[1]) and p.poll() is None and time.monotonic()