# -*- coding: utf-8 -*- """用现场 config 连跑 150 秒,盯状态机有没有卡住/抛异常。""" import io, json, os, sys, time, tkinter as tk sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') HERE = os.path.dirname(os.path.abspath(__file__)); ROOT = os.path.dirname(HERE) sys.path.insert(0, ROOT); os.chdir(ROOT) from ui import app as A BASE = json.load(open('data/_diag/demo_config.json', encoding='utf-8')) BASE['ui'].update({'mode': 'window', 'borderless': False, 'width': 1440, 'height': 900, 'todo_thumb': False}) A.load_config = lambda path='config.json', _c=BASE: _c root = tk.Tk(); app = A.App(root); root.geometry('1440x900+0+0') app._login_user = 'demo'; app._login_pwd = '1' app.engine.login() t0 = time.time() while time.time() - t0 < 8: root.update() if app.ready: break time.sleep(0.02) print('ready', app.ready) seq = [] T0 = time.time() last = None stuck_since = None while time.time() - T0 < 150: root.update() st = app.engine.state kg = float(getattr(app.engine.scale, 'weight', 0) or 0) if st != last: seq.append((round(time.time() - T0, 1), st, round(kg, 2))) print(' %6.1fs %-12s %.2fkg 行数=%d' % (time.time() - T0, st, kg, len(getattr(app, '_all_rows', []) or []))) last = st stuck_since = time.time() elif st in ('CONFIRM', 'DONE') and time.time() - stuck_since > 25: print(' !! %s 已停留 %.0f 秒(kg=%.2f)' % (st, time.time() - stuck_since, kg)) stuck_since = time.time() time.sleep(0.05) print('轨迹:', ' → '.join('%s@%ss' % (s, t) for t, s, _ in seq)) print('记录文件:') p = BASE.get('record_file') if os.path.isfile(p): print(open(p, encoding='utf-8').read()[-400:]) else: print(' (没有)') try: app.engine.stop() except Exception: pass root.destroy()