Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-93312: Add os.PIDFD_NONBLOCK #93313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down