Document how import chains are affected by `sys.setrecursionlimit`
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
While working on a very large Python codebase, I ran into some undocumented behaviour.
A chain of imports (i.e. one module imports another, which imports another, which imports another) will cause a RecursionError to be raised if the Python recursion limit is not high enough. (Note, there is no recursion involved.)
Longer chains of imports can be enabled by increasing the recursion limit. But the limit has no effect beyond a certain point (around 10,000). (I believe this is due to Py_C_RECURSION_LIMIT, mentioned in by Serhiy Storchaka.)
A workaround is available: you can import the modules in a different order.
I've created a repository with more analysis and scripts to reproduce the problem. I also started a Discuss topic on the subject.
From what I understand, this is a complex problem that is unlikely to be fixed. But I think it would be helpful to document this, probably in the docs for sys.setrecursionlimit.
I would be happy to try to do a pull request, assuming the core team agree that it should be added.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 sys.setrecursionlimit 文件開始,並使用連結的 import-recursion-demo 儲存庫及其重現腳本來驗證行為。完成標準是記錄多長的匯入鏈會觸發 RecursionError、大致的上限,以及替代的匯入順序解決方法。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- documentation
- Issue 類型
- 文件
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 58/100