Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Extend selectors module to support platform-specific events #144211

Copy link
Copy link
@giampaolo

Description

@giampaolo
Issue body actions

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, #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 #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.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtype-featureA feature request or enhancementA feature request or enhancement
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.