# Failed: 来自 pytest-timeout 的超时 (>60.0s)。
=== 1 failed in 60.12s ===

- **ID:** `python/pytest-timeout-thread-stuck`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

测试在没有超时的情况下阻塞在网络调用、锁或线程 join 上；pytest-timeout 的信号方法无法中断 C 层阻塞调用或非主线程。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.3.x | active | — | — |
| 2.4.x | active | — | — |

## 解决方案

1. **** (93% 成功率)
   ```
   import requests
resp = requests.get(url, timeout=5)

# For threads:
thread.join(timeout=5)
assert not thread.is_alive()
   ```
2. **** (88% 成功率)
   ```
   # pyproject.toml
[tool.pytest.ini_options]
timeout = 30
timeout_method = "signal"
# Ensure no test spawns daemon threads that outlive the test
   ```

## 无效尝试

- **** — Merely postpones failure; the underlying hang remains and CI time balloons. Flaky suites still fail on slower machines. (70% 失败率)
- **** — The thread method cannot kill the stuck thread; it only raises in the main thread, leaving resources leaked and the process hung. (80% 失败率)
