From ddb1eb67103f4a57b260613593c46754b03303ce Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Sat, 28 May 2022 07:57:36 +0000 Subject: [PATCH 1/3] add PIDFD_NONBLOCK --- Doc/library/os.rst | 14 ++++++++++---- Doc/whatsnew/3.12.rst | 7 +++++++ Modules/posixmodule.c | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index dc0f2e4158ac0e..dd2962e3f5bf5b 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3897,16 +3897,22 @@ 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. + + .. 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 8a7309726ed2ac..7c560d73a5fc6f 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/Modules/posixmodule.c b/Modules/posixmodule.c index 0a72aca8d51fa2..6883ad0c12ccf1 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; From 8a74c00faf116807527ab0dadad5b0861da85b11 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 28 May 2022 08:02:56 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-05-28-08-02-55.gh-issue-93312.HY0Uzj.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-05-28-08-02-55.gh-issue-93312.HY0Uzj.rst 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 00000000000000..6c8f7142fe338f --- /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` to open a file descriptor +for a process with :func:`os.pidfd_open` in non-blocking mode. +Patch by Kumar Aditya. From 4ff2d213e470b9f64eff7652afdfe642fb7783aa Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Tue, 31 May 2022 07:15:27 +0000 Subject: [PATCH 3/3] fix docs --- Doc/library/os.rst | 3 +++ .../Library/2022-05-28-08-02-55.gh-issue-93312.HY0Uzj.rst | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index dd2962e3f5bf5b..1f434a1c5b62fb 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3909,6 +3909,9 @@ written in Python, such as a mail server's external command delivery program. .. 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 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 index 6c8f7142fe338f..f11d04f63532f3 100644 --- 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 @@ -1,3 +1,3 @@ -Add :data:`os.PIDFD_NONBLOCK` to open a file descriptor +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. +Patch by Kumar Aditya.