fix: market_watch/mr_scanner/s2_scanner 统一加装自愈式单例守卫

- 与price_monitor同模式: 新鲜实例在跑则退出, 卡死超时则SIGKILL接管
- market_watch 600s / 扫描器 1500s 阈值
- 落实2026-08-05重型任务资源约束铁律第4条
This commit is contained in:
xxm
2026-08-05 15:23:00 +08:00
parent 4baa1542ca
commit 2bca726418
3 changed files with 100 additions and 0 deletions
+33
View File
@@ -284,8 +284,41 @@ def check_vmr(klines, mkt_adx=None):
}
def _singleton_guard(max_age_sec, script_tag):
"""自愈式单例守卫(2026-08-05 进程堆积事故后统一加装)"""
import subprocess as _sp, os as _os, sys as _sys
my_pid = _os.getpid()
try:
out = _sp.run(["ps", "-C", "python3", "-o", "pid,etimes,cmd"],
capture_output=True, text=True, timeout=10).stdout
for line in out.splitlines():
if script_tag not in line:
continue
parts = line.split(None, 2)
if len(parts) < 3:
continue
try:
pid = int(parts[0]); age = int(parts[1])
except ValueError:
continue
if pid == my_pid:
continue
if age > max_age_sec:
try:
_os.kill(pid, 9)
print(f"[guard] SIGKILL卡死实例 pid={pid} age={age}s", flush=True)
except ProcessLookupError:
pass
else:
print(f"[guard] 已有新鲜实例 pid={pid} age={age}s 在跑, 本实例退出", flush=True)
_sys.exit(0)
except Exception as _e:
print(f"[guard] 守卫异常(放行): {_e}", flush=True)
def main():
force = "--force" in sys.argv
_singleton_guard(1500, "mr_scanner.py")
top_n = TOP_N
if "--top" in sys.argv:
try: