python / python/cpython

Document how import chains are affected by `sys.setrecursionlimit`

Đang mở
#128,544 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

docs
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với tài liệu về sys.setrecursionlimit và sử dụng repository import-recursion-demo được liên kết cùng các script tái hiện của repository này để xác minh hành vi. Công việc được xem là hoàn tất khi đã ghi lại độ dài mà chuỗi import cần đạt tới để kích hoạt RecursionError, giới hạn trên gần đúng và workaround sử dụng thứ tự import thay thế.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
documentation
Loại issue
Tài liệu
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
58/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.