{
  "id": "python/pytest-xdist-worker-crash-fork",
  "signature": "worker 'gw3' crashed while running 'tests/test_heavy.py::test_parallel'\n[gw3] node down: Not properly terminated\nReplacing crashed worker gw3",
  "signature_zh": "worker 'gw3' 在运行 'tests/test_heavy.py::test_parallel' 时崩溃\n[gw3] 节点宕机: 未正常终止\n正在替换崩溃的 worker gw3",
  "regex": "worker\\ 'gw3'\\ crashed\\ while\\ running\\ 'tests/test_heavy\\.py::test_parallel'\\\n\\[gw3\\]\\ node\\ down:\\ Not\\ properly\\ terminated\\\nReplacing\\ crashed\\ worker\\ gw3",
  "domain": "python",
  "category": "system_error",
  "subcategory": null,
  "root_cause": "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "测试在 xdist worker 内使用了 fork() 或 fork 启动方式的 multiprocessing；fork 一个已经包含线程的进程（xdist worker 就是）会导致死锁或 SIGSEGV。",
  "versions": [
    {
      "version": "3.6.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.7.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Masks the crash and slows the suite; the underlying fork-in-threaded-process bug still occurs on every run.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Defeats parallelism entirely; on large suites CI time can triple and the test that triggered the crash still runs unsafely.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "import multiprocessing as mp\n\nif __name__ == '__main__':\n    mp.set_start_method('spawn', force=True)\n\n# In test fixture:\nctx = mp.get_context('spawn')\nwith ctx.Pool(2) as p:\n    ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.88,
      "how": "# In conftest.py\ndef pytest_collection_modifyitems(items):\n    for it in items:\n        if 'heavy' in it.keywords:\n            it.add_marker(pytest.mark.xdist_group('serial'))\n\n# Run:\npytest -n auto --dist loadgroup",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2024-11-19",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}