[Python-checkins] GH-93312: Add os.PIDFD_NONBLOCK flag (#93313)

vstinner webhook-mailer at python.org
Tue May 31 06:52:02 EDT 2022


https://github.com/python/cpython/commit/a565ab0fd58bcd4bbc01084b74ef704a75084274
commit: a565ab0fd58bcd4bbc01084b74ef704a75084274
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: vstinner <vstinner at python.org>
date: 2022-05-31T12:51:29+02:00
summary:

GH-93312: Add os.PIDFD_NONBLOCK flag (#93313)

files:
A Misc/NEWS.d/next/Library/2022-05-28-08-02-55.gh-issue-93312.HY0Uzj.rst
M Doc/library/os.rst
M Doc/whatsnew/3.12.rst
M Modules/posixmodule.c

diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index dc0f2e4158ac0..1f434a1c5b62f 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -3897,16 +3897,25 @@ written in Python, such as a mail server's external command delivery program.
 
 .. function:: pidfd_open(pid, flags=0)
 
-   Return a file descriptor referring to the process *pid*.  This descriptor can
-   be used to perform process management without races and signals.  The *flags*
-   argument is provided for future extensions; no flag values are currently
-   defined.
+   Return a file descriptor referring to the process *pid* with *flags* set.
+   This descriptor can be used to perform process management without races
+   and signals.
 
    See the :manpage:`pidfd_open(2)` man page for more details.
 
    .. availability:: Linux 5.3+
    .. versionadded:: 3.9
 
+   .. data:: PIDFD_NONBLOCK
+
+      This flag indicates that the file descriptor will be non-blocking.
+      If the process referred to by the file descriptor has not yet terminated,
+      then an attempt to wait on the file descriptor using :manpage:`waitid(2)`
+      will immediately return the error :data:`~errno.EAGAIN` rather than blocking.
+
+   .. availability:: Linux 5.10+
+   .. versionadded:: 3.12
+
 
 .. function:: plock(op)
 
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index 8a7309726ed2a..7c560d73a5fc6 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -90,6 +90,13 @@ New Modules
 Improved Modules
 ================
 
+os
+--
+
+* Add :data:`os.PIDFD_NONBLOCK` to open a file descriptor
+  for a process with :func:`os.pidfd_open` in non-blocking mode.
+  (Contributed by Kumar Aditya in :gh:`93312`.)
+
 
 Optimizations
 =============
diff --git a/Misc/NEWS.d/next/Library/2022-05-28-08-02-55.gh-issue-93312.HY0Uzj.rst b/Misc/NEWS.d/next/Library/2022-05-28-08-02-55.gh-issue-93312.HY0Uzj.rst
new file mode 100644
index 0000000000000..f11d04f63532f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-28-08-02-55.gh-issue-93312.HY0Uzj.rst
@@ -0,0 +1,3 @@
+Add :data:`os.PIDFD_NONBLOCK` flag to open a file descriptor
+for a process with :func:`os.pidfd_open` in non-blocking mode.
+Patch by Kumar Aditya.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 0a72aca8d51fa..6883ad0c12ccf 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -15255,6 +15255,9 @@ all_ins(PyObject *m)
 #ifdef P_PIDFD
     if (PyModule_AddIntMacro(m, P_PIDFD)) return -1;
 #endif
+#ifdef PIDFD_NONBLOCK
+    if (PyModule_AddIntMacro(m, PIDFD_NONBLOCK)) return -1;
+#endif
 #endif
 #ifdef WEXITED
     if (PyModule_AddIntMacro(m, WEXITED)) return -1;



More information about the Python-checkins mailing list