快速结论:该问题出现在 Gradio 仓库的 Python CI 非 flaky 测试任务中:pytest -n auto 在装有 psutil 的 4-vCPU ubuntu-latest runner 上只创建 2 个 xdist worker,导致并行测试步骤耗时从 213–248s 增至 418–436s。优先排查 xdist worker 数量是否与 runner 的 vCPU 数一致。
适用环境:Gradio 仓库 GitHub Actions;ubuntu-latest 4-vCPU runner;Python CI 工作流 .github/workflows/test-python.yml 中的 test-ubuntu-latest-not-flaky 任务;依赖环境中包含 psutil(由 #13998 引入,用于 launch(replicas="auto"));Gradio 7.0-dev 及其分支。
最快修复方案:暂无确认的一步修复方案。Issue 中验证了根因并提出了 -n logical 方案,对应修复为 #14032,但未在本 Issue 内确认合并后的效果。
注意事项:-n logical 会让同一 runner 上并行运行的测试更多,涉及固定端口(如 test_autoscaling.py 使用的 7952)的测试需要确认与其他测试的端口扫描范围 7860–7959 不冲突,否则可能出现偶发端口占用失败。
问题场景
在 Gradio 仓库的 GitHub Actions CI 中,test-ubuntu-latest-not-flaky 任务通过 pytest -n auto 并行执行测试。2026-10-29 时,“Run parallel tests”步骤耗时 213–248s;自 #13998(launch(replicas="auto"))合入后,7.0-dev 及其分支上该步骤耗时变为 418–436s。日志显示 xdist 只创建了 created: 2/2 workers,而 runner 实际为 4 vCPU。
报错原文
Python CI: the ubuntu not-flaky test job runs only 2 xdist workers and has doubled in length
created: 2/2 workers
Run parallel tests: 418–436s
原因分析
根因不是新增的 autoscaling 测试本身:该测试本地约 12s。真正原因是 #13998 将 psutil 加入 requirements.txt 后,pytest-xdist 的 -n auto 在 psutil 存在时会按物理核心数计算 worker 数量,而在没有 psutil 时使用 os.cpu_count()。因此 4-vCPU runner 从之前的 created: 4/4 workers(对应运行 40961972861、40964665302,耗时 213–248s)退化为 created: 2/2 workers(对应运行 40946598832、41093811175、41091797181,耗时 418–436s)。
环境排查
- 确认 GitHub Actions runner 的实际 vCPU 数量(
ubuntu-latest为 4 vCPU)。 - 确认
requirements.txt中是否存在psutil,以及它是否由launch(replicas="auto")相关改动引入。 - 检查 CI 日志中 xdist 实际创建的 worker 数,例如
created: 2/2 workers或created: 4/4 workers。 - 确认
.github/workflows/test-python.yml中test-ubuntu-latest-not-flaky任务的 pytest 参数。 - 检查是否存在测试绑定固定端口,例如
test_autoscaling.py使用的 7952。
解决步骤
- 在
test-ubuntu-latest-not-flaky任务的 pytest 命令中,将-n auto改为-n logical,使 worker 数量按逻辑 CPU 计算,而不受psutil是否安装影响(对应 #14032 的修复方式)。 - 可优先尝试追加
--durations=25,让 CI 日志显示最慢的测试,便于后续定位性能退化。 - 检查并调整绑定固定端口的测试,确保其端口不在其他测试
launch()扫描的 7860–7959 范围内,或使其在更多 worker 并行时不会发生端口冲突。 - 本地可用相同测试选择(
-m "not flaky and not serial")对比 2 个与 4 个 worker 的耗时,Issue 中测得分别为 252s 和 132s,最慢单测为 17s。
验证方法
重新运行 test-ubuntu-latest-not-flaky 任务,确认 CI 日志中的 xdist worker 数变为 created: 4/4 workers,且“Run parallel tests”步骤耗时明显回落。若同时加入 --durations=25,可查看慢测试列表,确认没有新的环境相关超时或端口冲突。
参考来源
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。
![[Bug]: MinerU 3.x /file_parse upload ignores the pipeline context and stays open after the run is cancelled](https://www.chat-gpts.plus/wp-content/uploads/2026/10/21572-82f3bc14-768x403.jpg)
![[Bug]: MinerU polling ignores cancellation and reports the wait timeout as a missing result](https://www.chat-gpts.plus/wp-content/uploads/2026/10/21570-666056f1-768x403.jpg)
![2024/01/10 19:17:53 [W] [service.go:132] login to server failed: dial tcp 44.237.78.176:7000: connect: connection refused](https://www.chat-gpts.plus/wp-content/uploads/2026/10/6988-22b6a761-768x403.jpg)