File size: 1,279 Bytes
638cad0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import requests, time
BASE = "http://127.0.0.1:8000"
H = {"Authorization": "Bearer sk-AQM1TfaVx2VSzEoTLiV1J2NH1B92g6AI"}
TASK_ID = "concurrent_demo_006"
seen_running = False
for i in range(25):
time.sleep(10)
try:
r2 = requests.get(BASE + "/api/product-visual/tasks?ids=" + TASK_ID, headers=H, timeout=60)
tt = r2.json().get("items", [{}])[0]
except Exception as exc:
print(f" [{i*10+10}s] 查询异常: {str(exc)[:50]}")
continue
items = tt.get("items", [])
if not items:
print(f" [{i*10+10}s] 规划中(stage={tt.get('plan_stage')})")
continue
statuses = [it.get("status") for it in items]
running = statuses.count("running")
queued = statuses.count("queued")
success = statuses.count("success")
print(f" [{i*10+10}s] 运行中={running} 排队={queued} 成功={success} 待提交={statuses.count('pending')} 总={len(statuses)}")
if running >= 2 and not seen_running:
seen_running = True
print(f" >>> 并发确认:{running} 屏同时 running")
if success == len(statuses):
print(" >>> 全部完成")
break
if tt.get("status") in ("failed", "partial_failed"):
print(" >>> 任务结束:", tt.get("status"))
break
|