python / python/cpython

Extend `selectors` module to support platform-specific events

Offen
#144,211 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

extension-modules type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der API des selectors-Moduls, insbesondere KqueueSelector, PollSelector, register(), modify() und select(), und lies dann select.kevent sowie den asyncio-Anwendungsfall in Lib/asyncio/unix_events.py rund um die Zeilen 857-891. Ermittle, wie plattformspezifische Ereignisse registriert und durch select() dargestellt werden sollten; als abgeschlossen gilt die Arbeit, wenn ein festgelegtes API-Design vorliegt, das die genannten OS-Ereignisse unterstützt, ohne den bestehenden read/write-Vertrag zu brechen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
operating-systems
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.