feat: integrate native diagnostics and coordinated CBB transactions

This commit is contained in:
阿白叔 committed 2026-11-05 23:18:00 +08:00
1 parent 9e230e1a46
commit da67de026f
91 files changed
+14370 -435

No files matched your search

+34
View File
@@ -91,6 +91,35 @@ def require_document_identity(document, job):
return integration
class ProcessWatch:
"""Hold this task's native handles; repeated COM attach polls never run WMI."""
def __init__(self, pids):
self.pids = set(int(pid) for pid in pids if pid)
self.handles = None
def __enter__(self):
return self
def alive(self):
import pywintypes, win32api, win32con, win32event
if self.handles is None:
self.handles = []
try:
for pid in self.pids:
try:
self.handles.append(win32api.OpenProcess(win32con.SYNCHRONIZE, False, pid))
except pywintypes.error as error:
if error.winerror != 87: raise
except Exception:
self.__exit__(None, None, None)
raise
return any(win32event.WaitForSingleObject(h, 0) != win32con.WAIT_OBJECT_0 for h in self.handles)
def __exit__(self, *_):
for handle in self.handles or (): handle.Close()
self.handles = []
def wait_for_target_document(job, app_provider, *, process_alive, emit=lambda **event: None,
error_reader=None, sleep=time.sleep):
"""Wait for the exact launched document; the parent process owns timeout."""
@@ -103,6 +132,11 @@ def wait_for_target_document(job, app_provider, *, process_alive, emit=lambda **
try:
app = app_provider()
document = app.ActiveDocument
if not document:
observation = ('PCB_DOCUMENT_NOT_READY', 'COM 已连接,尚无目标文档')
if observation != last_observation:
emit(stage='pcb_document_wait', error_code=observation[0], detail=observation[1])
last_observation = observation
if document:
try:
integration = require_document_identity(document, job)