Repository: python/cpython
Pull request: gh-127481: Add `EPOLLWAKEUP` to the `select` module
<!--
Thanks for your contribution!
Please read this comment in its entirety. It's quite important.

# Pull Request title

It should be in the following format:

```
gh-NNNNN: Summary of the changes made
```

Where: gh-NNNNN refers to the GitHub issue number.

Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue.

# Backport Pull Request title

If this is a backport PR (PR made against branches other than `main`),
please ensure that the PR title is in the following format:

```
[X.Y] <title from the original PR> (GH-NNNN)
```

Where: [X.Y] is the branch name, e.g. [3.6].

GH-NNNN refers to the PR number from `main`.

-->


<!-- gh-issue-number: gh-127481 -->
* Issue: gh-127481
<!-- /gh-issue-number -->


<!-- readthedocs-preview cpython-previews start -->
----
📚 Documentation preview 📚: https://cpython-previews--127482.org.readthedocs.build/

<!-- readthedocs-preview cpython-previews end -->

Problem statement:
Add `EPOLLWAKEUP` to the select module
# Feature or enhancement

### Proposal:

This issue suggests adding new select constants.

for example
```
fd = /* a socket object */
p = /* a epoll object */
/* It will prevent the system from hanging (e.g. low-power or standby) */
p.register(fd, EPOLLWAKEUP)
```

### Has this already been discussed elsewhere?

No response given

### Links to previous discussion of this feature:

_No response_

<!-- gh-linked-prs -->
### Linked PRs
* gh-127482
<!-- /gh-linked-prs -->

Hints from issue discussion:

Commit message: Add latest constant for select

Patch to review:
diff --git a/Doc/library/select.rst b/Doc/library/select.rst
index f23a249f44b485..60e3be03d5051e 100644
--- a/Doc/library/select.rst
+++ b/Doc/library/select.rst
@@ -280,43 +280,47 @@ Edge and Level Trigger Polling (epoll) Objects
 
    *eventmask*
 
-   +-------------------------+-----------------------------------------------+
-   | Constant                | Meaning                                       |
-   +=========================+===============================================+
-   | :const:`EPOLLIN`        | Available for read                            |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLOUT`       | Available for write                           |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLPRI`       | Urgent data for read                          |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLERR`       | Error condition happened on the assoc. fd     |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLHUP`       | Hang up happened on the assoc. fd             |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLET`        | Set Edge Trigger behavior, the default is     |
-   |                         | Level Trigger behavior                        |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLONESHOT`   | Set one-shot behavior. After one event is     |
-   |                         | pulled out, the fd is internally disabled     |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLEXCLUSIVE` | Wake only one epoll object when the           |
-   |                         | associated fd has an event. The default (if   |
-   |                         | this flag is not set) is to wake all epoll    |
-   |                         | objects polling on a fd.                      |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLRDHUP`     | Stream socket peer closed connection or shut  |
-   |                         | down writing half of connection.              |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLRDNORM`    | Equivalent to :const:`EPOLLIN`                |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLRDBAND`    | Priority data band can be read.               |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLWRNORM`    | Equivalent to :const:`EPOLLOUT`               |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLWRBAND`    | Priority data may be written.                 |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLMSG`       | Ignored.                                      |
-   +-------------------------+-----------------------------------------------+
+   +---------------------------+-----------------------------------------------+
+   | Constant                  | Meaning                                       |
+   +===========================+===============================================+
+   | :const:`EPOLLIN`          | Available for read                            |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLOUT`         | Available for write                           |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLPRI`         | Urgent data for read                          |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLERR`         | Error condition happened on the assoc. fd     |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLHUP`         | Hang up happened on the assoc. fd             |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLET`          | Set Edge Trigger behavior, the default is     |
+   |                           | Level Trigger behavior                        |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLONESHOT`     | Set one-shot behavior. After one event is     |
+   |                           | pulled out, the fd is internally disabled     |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLEXCLUSIVE`   | Wake only one epoll object when the           |
+   |                           | associated fd has an event. The default (if   |
+   |                           | this flag is not set) is to wake all epoll    |
+   |                           | objects polling on a fd.                      |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLRDHUP`       | Stream socket peer closed connection or shut  |
+   |                           | down writing half of connection.              |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLRDNORM`      | Equivalent to :const:`EPOLLIN`                |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLRDBAND`      | Priority data band can be read.               |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLWRNORM`      | Equivalent to :const:`EPOLLOUT`               |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLWRBAND`      | Priority data may be written.                 |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLMSG`         | Ignored.                                      |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLL_URING_WAKE` | Optimizes event wake-up using io_uring.       |                                              |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLWAKEUP`      | Prevents sleep during event waiting.          |                                              |
+   +---------------------------+-----------------------------------------------+
 
    .. versionadded:: 3.6
       :const:`EPOLLEXCLUSIVE` was added.  It's only supported by Linux Kernel 4.5
diff --git a/Misc/NEWS.d/next/Library/2024-12-01-23-18-43.gh-issue-127481.K36AoP.rst b/Misc/NEWS.d/next/Library/2024-12-01-23-18-43.gh-issue-127481.K36AoP.rst
new file mode 100644
index 00000000000000..1afc464c68eca5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-12-01-23-18-43.gh-issue-127481.K36AoP.rst
@@ -0,0 +1,2 @@
+Add the ``EPOLL_URING_WAKE``, ``EPOLLWAKEUP`` constants to the :mod:`select`
+module.
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 6ced71cca73178..62ceadc5f1a504 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -2715,6 +2715,12 @@ _select_exec(PyObject *m)
 #ifdef EPOLLMSG
     ADD_INT(EPOLLMSG);
 #endif
+#ifdef EPOLL_URING_WAKE
+    ADD_INT(EPOLL_URING_WAKE);
+#endif
+#ifdef EPOLLWAKEUP
+    ADD_INT(EPOLLWAKEUP);
+#endif
 
 #ifdef EPOLL_CLOEXEC
     ADD_INT(EPOLL_CLOEXEC);


Code review comments:
diff_hunk: @@ -280,43 +280,47 @@ Edge and Level Trigger Polling (epoll) Objects
 
    *eventmask*
 
-   +-------------------------+-----------------------------------------------+
-   | Constant                | Meaning                                       |
-   +=========================+===============================================+
-   | :const:`EPOLLIN`        | Available for read                            |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLOUT`       | Available for write                           |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLPRI`       | Urgent data for read                          |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLERR`       | Error condition happened on the assoc. fd     |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLHUP`       | Hang up happened on the assoc. fd             |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLET`        | Set Edge Trigger behavior, the default is     |
-   |                         | Level Trigger behavior                        |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLONESHOT`   | Set one-shot behavior. After one event is     |
-   |                         | pulled out, the fd is internally disabled     |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLEXCLUSIVE` | Wake only one epoll object when the           |
-   |                         | associated fd has an event. The default (if   |
-   |                         | this flag is not set) is to wake all epoll    |
-   |                         | objects polling on a fd.                      |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLRDHUP`     | Stream socket peer closed connection or shut  |
-   |                         | down writing half of connection.              |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLRDNORM`    | Equivalent to :const:`EPOLLIN`                |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLRDBAND`    | Priority data band can be read.               |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLWRNORM`    | Equivalent to :const:`EPOLLOUT`               |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLWRBAND`    | Priority data may be written.                 |
-   +-------------------------+-----------------------------------------------+
-   | :const:`EPOLLMSG`       | Ignored.                                      |
-   +-------------------------+-----------------------------------------------+
+   +---------------------------+-----------------------------------------------+
+   | Constant                  | Meaning                                       |
+   +===========================+===============================================+
+   | :const:`EPOLLIN`          | Available for read                            |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLOUT`         | Available for write                           |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLPRI`         | Urgent data for read                          |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLERR`         | Error condition happened on the assoc. fd     |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLHUP`         | Hang up happened on the assoc. fd             |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLET`          | Set Edge Trigger behavior, the default is     |
+   |                           | Level Trigger behavior                        |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLONESHOT`     | Set one-shot behavior. After one event is     |
+   |                           | pulled out, the fd is internally disabled     |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLEXCLUSIVE`   | Wake only one epoll object when the           |
+   |                           | associated fd has an event. The default (if   |
+   |                           | this flag is not set) is to wake all epoll    |
+   |                           | objects polling on a fd.                      |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLRDHUP`       | Stream socket peer closed connection or shut  |
+   |                           | down writing half of connection.              |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLRDNORM`      | Equivalent to :const:`EPOLLIN`                |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLRDBAND`      | Priority data band can be read.               |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLWRNORM`      | Equivalent to :const:`EPOLLOUT`               |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLWRBAND`      | Priority data may be written.                 |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLMSG`         | Ignored.                                      |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLL_URING_WAKE` | Optimizes event wake-up using io_uring.       |                                              |
+   +---------------------------+-----------------------------------------------+
+   | :const:`EPOLLWAKEUP`      | Prevents sleep during event waiting.          |                                              |
+   +---------------------------+-----------------------------------------------+
path: Doc/library/select.rst
text: @user1:
```suggestion
   +---------------------------+-----------------------------------------------+
   | :const:`EPOLL_URING_WAKE` | Optimizes event wake-up using io_uring.       |
   +---------------------------+-----------------------------------------------+
   | :const:`EPOLLWAKEUP`      | Prevents sleep during event waiting.          |
   +---------------------------+-----------------------------------------------+
```

You seem to have additional `|` at the end.

@author:
Sorry. I'm addicted to space key ;)

diff_hunk: @@ -0,0 +1,2 @@
+Add the ``EPOLL_URING_WAKE``, ``EPOLLWAKEUP`` constants to the :mod:`select`
path: Misc/NEWS.d/next/Library/2024-12-01-23-18-43.gh-issue-127481.K36AoP.rst
text: @user1:
```suggestion
Add the ``EPOLL_URING_WAKE`` and ``EPOLLWAKEUP`` constants to the :mod:`select`
```