fix(hooks): replace DETACHED_PROCESS with CREATE_NO_WINDOW on Windows

This commit is contained in:
himanshupatro-334
2026-07-28 09:37:39 +01:00
committed by safishamsi
parent 16442303e1
commit 3bac3df666
3 changed files with 5 additions and 4 deletions
+1
View File
@@ -4,3 +4,4 @@
worked/**/*.html linguist-vendored=true
graphify-out/**/*.html linguist-vendored=true
*.html linguist-detectable=false
graphify-out/graph.json merge=graphify
+2 -2
View File
@@ -215,7 +215,7 @@ except Exception as exc:
# requires Python, so we let Python do the detaching: a tiny outer process spawns
# the real rebuild fully detached and returns immediately, so the hook never
# blocks. POSIX uses start_new_session (the setsid equivalent); Windows uses
# DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP, breaking away from any job object
# CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP, breaking away from any job object
# when allowed. This payload is carried inside a shell double-quoted -c argument,
# so it deliberately uses only single-quoted Python strings (no ", $, ` or \\).
_LAUNCHER_TEMPLATE = """\
@@ -232,7 +232,7 @@ except OSError:
_kw = dict(stdout=_out, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL, cwd=os.getcwd(), close_fds=True)
_cmd = [sys.executable, '-c', _src]
if os.name == 'nt':
_flags = 0x00000008 | 0x00000200 # DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP
_flags = 0x08000000 | 0x00000200 # CREATE_NO_WINDOW | CREATE_NEW_PROCESS_GROUP
try:
subprocess.Popen(_cmd, creationflags=_flags | 0x01000000, **_kw) # + CREATE_BREAKAWAY_FROM_JOB
except OSError:
+2 -2
View File
@@ -248,10 +248,10 @@ def test_hooks_do_not_use_nohup(name, script):
@pytest.mark.parametrize("name,script", _HOOK_SCRIPTS)
def test_hooks_use_cross_platform_detach(name, script):
"""The replacement detaches via Python: start_new_session on POSIX and
DETACHED_PROCESS|CREATE_NEW_PROCESS_GROUP on Windows (#1161)."""
CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP on Windows (#1161)."""
assert "subprocess.Popen" in script
assert "start_new_session=True" in script, f"{name} missing POSIX detach"
assert "0x00000008" in script, f"{name} missing Windows DETACHED_PROCESS flag"
assert "0x08000000" in script, f"{name} missing Windows CREATE_NO_WINDOW flag"
assert "0x00000200" in script, f"{name} missing CREATE_NEW_PROCESS_GROUP flag"