Detach frozen service console environment

This commit is contained in:
王鹏
2026-10-10 21:47:46 +08:00
parent e1c58d8117
commit 91347be29e
2 changed files with 14 additions and 0 deletions

View File

@@ -620,6 +620,7 @@ def _restart_backend(
cwd=cwd, cwd=cwd,
stdin=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
shell=False, shell=False,
env=_service_console_environment(),
creationflags=_backend_console_creation_flags(), creationflags=_backend_console_creation_flags(),
) )
else: else:
@@ -668,6 +669,13 @@ def _service_console_launcher() -> list[str]:
return [sys.executable, str(console_runner)] return [sys.executable, str(console_runner)]
def _service_console_environment() -> dict[str, str]:
environment = os.environ.copy()
if getattr(sys, "frozen", False):
environment["PYINSTALLER_RESET_ENVIRONMENT"] = "1"
return environment
def _restart_ssm_backend( def _restart_ssm_backend(
command: list[str], command: list[str],
cwd: Path, cwd: Path,

View File

@@ -84,6 +84,12 @@ class DeployerTests(unittest.TestCase):
self.assertEqual(launcher, [deployer_module.sys.executable, "--service-console"]) self.assertEqual(launcher, [deployer_module.sys.executable, "--service-console"])
def test_frozen_service_console_starts_as_independent_pyinstaller_instance(self):
with patch.object(deployer_module.sys, "frozen", True, create=True):
environment = deployer_module._service_console_environment()
self.assertEqual(environment["PYINSTALLER_RESET_ENVIRONMENT"], "1")
def test_extracts_backend_port_from_java_system_property(self): def test_extracts_backend_port_from_java_system_property(self):
extract_port = getattr(deployer_module, "_extract_server_port", lambda command: None) extract_port = getattr(deployer_module, "_extract_server_port", lambda command: None)