Extend `selectors` module to support platform-specific events
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
The selectors module API is deliberately very narrow:
- The
register()/modify()methods only accepteventsas a bitmask ofEVENT_READ|EVENT_WRITE - The
select()method only ever returns combinations ofEVENT_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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par l’API du module selectors, en particulier KqueueSelector, PollSelector, register(), modify() et select(), puis lisez select.kevent et le cas d’utilisation de asyncio dans Lib/asyncio/unix_events.py autour des lignes 857-891. Déterminez comment les événements spécifiques à la plateforme doivent être enregistrés et représentés par select() ; le travail est terminé lorsqu’une conception d’API arrêtée prend en charge les événements d’OS cités sans rompre le contrat read/write existant.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- operating-systems
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100