Download pv_concurrent_test.py from zlcy/study: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/zlcy/study/resolve/main/pv_concurrent_test.py
- Command line
-
hf download hf://spaces/zlcy/study/pv_concurrent_test.py
-
curl -L -o pv_concurrent_test.py https://huggingface.co/spaces/zlcy/study/resolve/main/pv_concurrent_test.py
1.28 kB
| 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 | |