python
system_error
ai_generated
partial
worker 'gw3' 在运行 'tests/test_heavy.py::test_parallel' 时崩溃 [gw3] 节点宕机: 未正常终止 正在替换崩溃的 worker gw3
worker 'gw3' crashed while running 'tests/test_heavy.py::test_parallel' [gw3] node down: Not properly terminated Replacing crashed worker gw3
ID: python/pytest-xdist-worker-crash-fork
80%修复率
82%置信度
0证据数
2024-11-19首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.6.x | active | — | — | — |
| 3.7.x | active | — | — | — |
根因分析
测试在 xdist worker 内使用了 fork() 或 fork 启动方式的 multiprocessing;fork 一个已经包含线程的进程(xdist worker 就是)会导致死锁或 SIGSEGV。
English
A test uses fork() or multiprocessing with the fork start method inside an xdist worker; forking a process that already has threads (xdist workers do) leads to deadlocks or SIGSEGV.
解决方案
-
93% 成功率
import multiprocessing as mp if __name__ == '__main__': mp.set_start_method('spawn', force=True) # In test fixture: ctx = mp.get_context('spawn') with ctx.Pool(2) as p: ... -
88% 成功率
# In conftest.py def pytest_collection_modifyitems(items): for it in items: if 'heavy' in it.keywords: it.add_marker(pytest.mark.xdist_group('serial')) # Run: pytest -n auto --dist loadgroup
无效尝试
常见但无效的做法:
-
80% 失败
Masks the crash and slows the suite; the underlying fork-in-threaded-process bug still occurs on every run.
-
70% 失败
Defeats parallelism entirely; on large suites CI time can triple and the test that triggered the crash still runs unsafely.