python / python/cpython

Extend `selectors` module to support platform-specific events

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

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

extension-modules type-feature
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ả

The selectors module API is deliberately very narrow:

  • The register() / modify() methods only accept events as a bitmask of EVENT_READ | EVENT_WRITE
  • The select() method only ever returns combinations of EVENT_READ | EVENT_WRITE

This design makes it impossible to use many platform-specific events provided by the underlying OS APIs (poll, epoll, kqueue). For example, https://github.com/python/cpython/issues/79698 describes a use case for EPOLLEXCLUSIVE on Linux. The biggest missed opportunity, however, is the inability to fully exploit kqueue() on BSD / macOS, which would allow async handling of regular files, signals, and others (see KQ_EVENT_*).

This limitation is relevant for asyncio, which uses the selectors module. For instance, on BSD / macOS, asyncio could be notified when a process terminates, enabling an optimization similar to https://github.com/python/cpython/pull/144047. Currenly asyncio on Linux already takes advantage of this approach via os.pidfd_open() + selectors.PollSelector (see source), but can't do the same for BSD / macOS because selectors.KqueueSelector doesn't allow registering custom select.kevent() objects.

Whereas it would be relatively easy to add a register_kevent() method, or to pass EPOLL* events directly to register(), it's less clear how the select() method should behave in this case, since it's apparently bound to the promise of returning either EVENT_READ or EVENT_WRITE.

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 API của mô-đun selectors, đặc biệt là KqueueSelector, PollSelector, register(), modify() và select(), sau đó đọc select.kevent và trường hợp sử dụng asyncio trong Lib/asyncio/unix_events.py quanh các dòng 857-891. Xác định cách các sự kiện dành riêng cho nền tảng nên được đăng ký và biểu diễn bởi select(); công việc được xem là hoàn tất khi có một thiết kế API đã thống nhất, hỗ trợ các sự kiện OS được nêu mà không phá vỡ hợp đồng read/write hiện có.

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
operating-systems
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/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.