"""把设备上 show_ui.pyc 的修改时间、以及内核报的 spec 一起打出来。 用于回答:"我明明重建安装了,为什么设备上跑的还是旧的?" """ import json import sys import urllib.request try: sys.stdout.reconfigure(encoding="utf-8", errors="replace") except Exception: pass URL = "http://127.0.0.1:15199" def call(path, payload=None, method="POST", timeout=60): data = json.dumps(payload, ensure_ascii=False).encode("utf-8") if payload is not None else None req = urllib.request.Request( URL + path, data=data, method=method, headers={"Content-Type": "application/json; charset=utf-8"}, ) with urllib.request.urlopen(req, timeout=timeout) as r: return json.loads(r.read().decode("utf-8")) # python_run 能在**内核进程里**跑(虽然是子进程,但能看文件系统) probe = r''' import os, sys, json, glob out = {} # Chaquopy 的 Python 根目录 for p in sys.path: if p and os.path.isdir(p): for name in ("show_ui.py", "show_ui.pyc", "bundled_tool_sources.pyc"): f = os.path.join(p, name) if os.path.exists(f): st = os.stat(f) out.setdefault("found", []).append({ "path": f, "size": st.st_size, "mtime": st.st_mtime, }) out["sys_path_head"] = sys.path[:6] out["has_wait_in_source"] = None # 试着从 bundled_tool_sources 里解出 show_ui 的源码,看看有没有 wait try: import base64, bundled_tool_sources src = bundled_tool_sources.sources().get("show_ui.py", "") out["has_wait_in_source"] = ("wait" in src) out["source_len"] = len(src) out["source_head"] = src[:200] except Exception as e: out["bundled_error"] = f"{type(e).__name__}: {e}" print(json.dumps(out, ensure_ascii=False)) ''' res = call("/api/tools/run", { "name": "python_run", "args": {"code": probe, "timeout": 30}, }, timeout=90) print(json.dumps(res, ensure_ascii=False, indent=2)[:2500])