Give PyErr_CheckSignals guide-level documentation
Chưa có ai nhận issue này.
- 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ả
Documentation
Compiled extensions that "want to be interruptible by user requests" need to call PyErr_CheckSignals periodically; when it returns -1, they should stop work, clean up after themselves, and return to the interpreter.
This function is not mentioned at all in the extending and embedding guide, and its reference documentation makes it sound unimportant. As a result, many extension authors are (it seems to me) not aware that it exists or that they ought to be calling it, and so many extensions that should be interruptible by user requests aren't. For example, if you execute this code
>>> import numpy as np
>>> rng = np.random.default_rng()
>>> x = rng.random(1000000000)
and then immediately hit control-C, you'll be waiting at least a few seconds before you get the prompt back.
PyErr_CheckSignals also has the unusual property of potentially executing arbitrary Python code before returning to its caller, which makes it easy to use unsafely. Making an extension interruptible throughout may necessitate calling PyErr_CheckSignals from innermost loops where one would ideally release the GIL, which makes that worse (see #133465).
Thus, I suggest that a guide to correct use of PyErr_CheckSignals should be added to the extending and embedding guide.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng việc đọc hướng dẫn về mở rộng và nhúng cùng với tài liệu tham khảo về PyErr_CheckSignals. Thêm hướng dẫn về cách sử dụng PyErr_CheckSignals an toàn, bao gồm việc xử lý giá trị trả về -1, dọn dẹp và khả năng thực thi mã Python tùy ý; tài liệu phải làm rõ cách các phần mở rộng có thể duy trì khả năng bị ngắt.
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 65/100