fix: finish cancelled diagnostic startup after target loading
This commit is contained in:
1 parent
d5d1a3deea
commit
845ae58690
3 files changed
+267
-3
No files matched your search
@@ -63,7 +63,7 @@ def _tip_target(snapshot):
|
||||
|
||||
|
||||
def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event: None,
|
||||
timeout_seconds=20, launcher_process=None):
|
||||
timeout_seconds=None, launcher_process=None):
|
||||
"""Normally close our empty PCB after a diagnosed database startup failure.
|
||||
|
||||
No COM attach: the global ROT can name another session. Only the exact
|
||||
@@ -90,6 +90,15 @@ def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event:
|
||||
if not pcb_pid or pcb_pid in baseline_pids:
|
||||
raise ValueError('STARTUP_PROCESS_UNCONFIRMED')
|
||||
expected = os.path.normcase(os.path.abspath(job['pcb']))
|
||||
cancelled_diagnostic = (job.get('diagnostic_only') is True
|
||||
and bool(job.get('cancel_signal')) and Path(job['cancel_signal']).exists()
|
||||
and isinstance(job.get('diagnostic_log_baseline'), dict)
|
||||
and {'started_ns', 'files'} <= job['diagnostic_log_baseline'].keys()
|
||||
and not (root/'save.log').exists())
|
||||
# Diagnostic close already owns a 30-second cleanup budget. Start it
|
||||
# once here; the empty-to-loaded transition never resets that deadline.
|
||||
if timeout_seconds is None:
|
||||
timeout_seconds = 30 if cancelled_diagnostic else 20
|
||||
deadline = time.monotonic() + max(0, timeout_seconds)
|
||||
sent = False
|
||||
declined_hwnd = None
|
||||
@@ -99,6 +108,14 @@ def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event:
|
||||
close_handle = None
|
||||
close_identity = None
|
||||
close_frame = None
|
||||
diagnostic_state = {'clicked': set()}
|
||||
def cleanup_post(hwnd, message):
|
||||
if (time.monotonic() >= deadline or _current_desktop_name() != desktop
|
||||
or win32event.WaitForSingleObject(close_handle, 0) != win32con.WAIT_TIMEOUT
|
||||
or residual_sessions._handle_identity(close_handle) != close_identity
|
||||
or win32process.GetWindowThreadProcessId(hwnd)[1] != pcb_pid):
|
||||
raise ValueError('STARTUP_ACTION_UNCONFIRMED')
|
||||
win32gui.PostMessage(hwnd, message, 0, 0)
|
||||
while True:
|
||||
records = [r for r in _process_details('ExpeditionPCB.exe') if r[0] == pcb_pid]
|
||||
if not records:
|
||||
@@ -133,6 +150,22 @@ def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event:
|
||||
or '-reusablecircuit' not in [a.casefold() for a in args]
|
||||
or expected not in [os.path.normcase(os.path.abspath(a)) for a in args[1:]]):
|
||||
raise ValueError('STARTUP_PROCESS_UNCONFIRMED')
|
||||
if cancelled_diagnostic and time.monotonic() < deadline:
|
||||
if close_handle is None:
|
||||
close_handle = handles.enter_context(residual_sessions._process_handle(pcb_pid))
|
||||
close_identity = residual_sessions._handle_identity(close_handle)
|
||||
if Path(close_identity['image']).name.casefold() != 'expeditionpcb.exe':
|
||||
raise ValueError('STARTUP_PROCESS_UNCONFIRMED')
|
||||
from .diagnostic_open import cancelled_startup_step
|
||||
closed, acted = cancelled_startup_step(job, pcb_pid, diagnostic_state,
|
||||
closed_frame=close_frame, deadline=deadline, post=cleanup_post, emit=emit)
|
||||
if closed is not None and not sent:
|
||||
sent, close_frame = True, closed
|
||||
emit(stage='startup_close_requested', pcb_pid=pcb_pid, hwnd=closed,
|
||||
document_identity='native_path_pid_logs', cleanup='cancelled_diagnostic')
|
||||
if acted:
|
||||
continue
|
||||
if not sent:
|
||||
windows = []
|
||||
def observe(hwnd, _):
|
||||
if (win32process.GetWindowThreadProcessId(hwnd)[1] == pcb_pid
|
||||
@@ -213,8 +246,9 @@ def close_failed_startup(job, pcb_pid, *, baseline_pids=(), emit=lambda **event:
|
||||
win32gui.EnumChildWindows(main[0], child, None)
|
||||
addresses = unreleased_addresses(job['lmc_file'], job['project'], job['pcb'])
|
||||
if len(main) == 1 and not unknown and not documents and (cancelled_open or not addresses):
|
||||
close_handle = handles.enter_context(residual_sessions._process_handle(pcb_pid))
|
||||
close_identity = residual_sessions._handle_identity(close_handle)
|
||||
if close_handle is None:
|
||||
close_handle = handles.enter_context(residual_sessions._process_handle(pcb_pid))
|
||||
close_identity = residual_sessions._handle_identity(close_handle)
|
||||
if Path(close_identity['image']).name.casefold() != 'expeditionpcb.exe':
|
||||
raise ValueError('STARTUP_PROCESS_UNCONFIRMED')
|
||||
win32gui.PostMessage(main[0], win32con.WM_CLOSE, 0, 0)
|
||||
|
||||
Reference in new issue
Block a user