fix: observe retained sessions without blocking independent libraries
This commit is contained in:
1 parent
6278091f21
commit
cb11624b68
9 files changed
+134
-7
No files matched your search
@@ -20,6 +20,8 @@ _FORCE_CLIENT_NAMES = {'expeditionpcb.exe', 'librarymanager.exe', 'viewdraw.exe'
|
||||
|
||||
def force_block_reason(row):
|
||||
"""A library path proves scope, never exclusive ownership of a server."""
|
||||
if row.get('runtime_phase') in ('NATIVE_CALL', 'CLOSING', 'UNCONFIRMED'):
|
||||
return '本工具的保存或原生调用尚未确认返回,请等待或查看原生提示'
|
||||
if row.get('scope_confirmed') is not True:
|
||||
return '进程归属未确认,不允许强制结束'
|
||||
name = str(row.get('name', '')).casefold()
|
||||
@@ -265,9 +267,14 @@ def inspect_residual_sessions(library, *, block_names=()):
|
||||
if scope is not False:
|
||||
candidates.append({**row, 'scope_confirmed': scope is True})
|
||||
windows = _process_windows({r['pid'] for r in candidates})
|
||||
from .session_record import active_write_records
|
||||
runtime_writes = active_write_records(library)
|
||||
sessions = []
|
||||
for row in candidates:
|
||||
item = dict(row)
|
||||
item['library'] = str(library)
|
||||
if runtime_writes and row['scope_confirmed']:
|
||||
item['runtime_phase'] = runtime_writes[0]['phase']
|
||||
try:
|
||||
item.update(_process_identity(row))
|
||||
target, detail = close_target(row['name'], windows.get(row['pid'], [])) if row['scope_confirmed'] else (
|
||||
@@ -351,6 +358,10 @@ def _force_close(row, *, stop=None):
|
||||
import win32api, win32con, win32event
|
||||
if stop is not None and stop.is_set():
|
||||
return {'release_status': 'CANCELLED', 'detail': '已停止释放'}
|
||||
if row.get('library'):
|
||||
from .session_record import active_write_records
|
||||
if active_write_records(row['library']):
|
||||
return {'release_status': 'WAITING', 'detail': '保存或原生调用尚未确认返回,未强制结束'}
|
||||
if reason := force_block_reason(row):
|
||||
return {'release_status': 'WAITING', 'detail': reason}
|
||||
with _process_handle(row['pid'], terminate=True) as handle:
|
||||
|
||||
Reference in new issue
Block a user