@@ -4491,83 +4491,50 @@ written in Python, such as a mail server's external command delivery program.
44914491 number is zero); the high bit of the low byte is set if a core file was
44924492 produced.
44934493
4494+ If there are no children that could be waited for, :exc: `ChildProcessError `
4495+ is raised.
4496+
44944497 :func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
44954498 exit code.
44964499
44974500 .. availability :: Unix, not Emscripten, not WASI.
44984501
44994502 .. seealso ::
45004503
4501- :func: `waitpid ` can be used to wait for the completion of a specific
4502- child process and has more options.
4504+ The other :func: `!wait* ` functions documented below can be used to wait for the
4505+ completion of a specific child process and have more options.
4506+ :func: `waitpid ` is the only one also available on Windows.
45034507
4504- .. function :: waitid(idtype, id, options, /)
45054508
4506- Wait for the completion of one or more child processes.
4507- *idtype * can be :data: `P_PID `, :data: `P_PGID `, :data: `P_ALL `, or
4508- :data: `P_PIDFD ` on Linux.
4509- *id * specifies the pid to wait on.
4510- *options * is constructed from the ORing of one or more of :data: `WEXITED `,
4511- :data: `WSTOPPED ` or :data: `WCONTINUED ` and additionally may be ORed with
4512- :data: `WNOHANG ` or :data: `WNOWAIT `. The return value is an object
4513- representing the data contained in the :c:type: `siginfo_t ` structure, namely:
4514- :attr: `si_pid `, :attr: `si_uid `, :attr: `si_signo `, :attr: `si_status `,
4515- :attr: `si_code ` or ``None `` if :data: `WNOHANG ` is specified and there are no
4516- children in a waitable state.
4517-
4518- .. availability :: Unix, not Emscripten, not WASI.
4519-
4520- .. versionadded :: 3.3
4521-
4522- .. data :: P_PID
4523- P_PGID
4524- P_ALL
4525-
4526- These are the possible values for *idtype * in :func: `waitid `. They affect
4527- how *id * is interpreted.
4528-
4529- .. availability :: Unix, not Emscripten, not WASI.
4530-
4531- .. versionadded :: 3.3
4532-
4533- .. data :: P_PIDFD
4534-
4535- This is a Linux-specific *idtype * that indicates that *id * is a file
4536- descriptor that refers to a process.
4537-
4538- .. availability :: Linux >= 5.4
4539-
4540- .. versionadded :: 3.9
4541-
4542- .. data :: WEXITED
4543- WSTOPPED
4544- WNOWAIT
4509+ .. function :: waitid(idtype, id, options, /)
45454510
4546- Flags that can be used in *options * in :func: `waitid ` that specify what
4547- child signal to wait for.
4511+ Wait for the completion of a child process.
45484512
4549- .. availability :: Unix, not Emscripten, not WASI.
4513+ *idtype * can be :data: `P_PID `, :data: `P_PGID `, :data: `P_ALL `, or (on Linux) :data: `P_PIDFD `.
4514+ The interpretation of *id * depends on it; see their individual descriptions.
45504515
4551- .. versionadded :: 3.3
4516+ *options * is an OR combination of flags. At least one of :data: `WEXITED `,
4517+ :data: `WSTOPPED ` or :data: `WCONTINUED ` is required;
4518+ :data: `WNOHANG ` and :data: `WNOWAIT ` are additional optional flags.
45524519
4520+ The return value is an object representing the data contained in the
4521+ :c:type: `!siginfo_t ` structure with the following attributes:
45534522
4554- .. data :: CLD_EXITED
4555- CLD_KILLED
4556- CLD_DUMPED
4557- CLD_TRAPPED
4558- CLD_STOPPED
4559- CLD_CONTINUED
4523+ * :attr: `!si_pid ` (process ID)
4524+ * :attr: `!si_uid ` (real user ID of the child)
4525+ * :attr: `!si_signo ` (always :data: `~signal.SIGCHLD `)
4526+ * :attr: `!si_status ` (the exit status or signal number, depending on :attr: `!si_code `)
4527+ * :attr: `!si_code ` (see :data: `CLD_EXITED ` for possible values)
45604528
4561- These are the possible values for :attr: `si_code ` in the result returned by
4562- :func: `waitid `.
4529+ If :data: `WNOHANG ` is specified and there are no matching children in the
4530+ requested state, ``None `` is returned.
4531+ Otherwise, if there are no matching children
4532+ that could be waited for, :exc: `ChildProcessError ` is raised.
45634533
45644534 .. availability :: Unix, not Emscripten, not WASI.
45654535
45664536 .. versionadded :: 3.3
45674537
4568- .. versionchanged :: 3.9
4569- Added :data: `CLD_KILLED ` and :data: `CLD_STOPPED ` values.
4570-
45714538
45724539.. function :: waitpid(pid, options, /)
45734540
@@ -4585,8 +4552,11 @@ written in Python, such as a mail server's external command delivery program.
45854552 ``-1 ``, status is requested for any process in the process group ``-pid `` (the
45864553 absolute value of *pid *).
45874554
4588- An :exc: `OSError ` is raised with the value of errno when the syscall
4589- returns -1.
4555+ *options * is an OR combination of flags. If it contains :data: `WNOHANG ` and
4556+ there are no matching children in the requested state, ``(0, 0) `` is
4557+ returned. Otherwise, if there are no matching children that could be waited
4558+ for, :exc: `ChildProcessError ` is raised. Other options that can be used are
4559+ :data: `WUNTRACED ` and :data: `WCONTINUED `.
45904560
45914561 On Windows: Wait for completion of a process given by process handle *pid *, and
45924562 return a tuple containing *pid *, and its exit status shifted left by 8 bits
@@ -4599,7 +4569,7 @@ written in Python, such as a mail server's external command delivery program.
45994569 :func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
46004570 exit code.
46014571
4602- .. availability :: Unix, not Emscripten, not WASI.
4572+ .. availability :: Unix, Windows, not Emscripten, not WASI.
46034573
46044574 .. versionchanged :: 3.5
46054575 If the system call is interrupted and the signal handler does not raise an
@@ -4612,9 +4582,9 @@ written in Python, such as a mail server's external command delivery program.
46124582 Similar to :func: `waitpid `, except no process id argument is given and a
46134583 3-element tuple containing the child's process id, exit status indication,
46144584 and resource usage information is returned. Refer to
4615- :mod: ` resource `. \ : func: `~ resource.getrusage ` for details on resource usage
4616- information. The option argument is the same as that provided to
4617- :func: `waitpid ` and :func: ` wait4 `.
4585+ :func: `resource.getrusage ` for details on resource usage information. The
4586+ * options * argument is the same as that provided to :func: ` waitpid ` and
4587+ :func: `wait4 `.
46184588
46194589 :func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
46204590 exitcode.
@@ -4625,17 +4595,122 @@ written in Python, such as a mail server's external command delivery program.
46254595.. function :: wait4(pid, options)
46264596
46274597 Similar to :func: `waitpid `, except a 3-element tuple, containing the child's
4628- process id, exit status indication, and resource usage information is returned.
4629- Refer to :mod: ` resource `. \ : func: `~ resource.getrusage ` for details on
4630- resource usage information. The arguments to :func: `wait4 ` are the same
4631- as those provided to :func: `waitpid `.
4598+ process id, exit status indication, and resource usage information is
4599+ returned. Refer to :func: `resource.getrusage ` for details on resource usage
4600+ information. The arguments to :func: `wait4 ` are the same as those provided
4601+ to :func: `waitpid `.
46324602
46334603 :func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
46344604 exitcode.
46354605
46364606 .. availability :: Unix, not Emscripten, not WASI.
46374607
46384608
4609+ .. data :: P_PID
4610+ P_PGID
4611+ P_ALL
4612+ P_PIDFD
4613+
4614+ These are the possible values for *idtype * in :func: `waitid `. They affect
4615+ how *id * is interpreted:
4616+
4617+ * :data: `!P_PID ` - wait for the child whose PID is *id *.
4618+ * :data: `!P_PGID ` - wait for any child whose progress group ID is *id *.
4619+ * :data: `!P_ALL ` - wait for any child; *id * is ignored.
4620+ * :data: `!P_PIDFD ` - wait for the child identified by the file descriptor
4621+ *id * (a process file descriptor created with :func: `pidfd_open `).
4622+
4623+ .. availability :: Unix, not Emscripten, not WASI.
4624+
4625+ .. note :: :data:`!P_PIDFD` is only available on Linux >= 5.4.
4626+
4627+ .. versionadded :: 3.3
4628+ .. versionadded :: 3.9
4629+ The :data: `!P_PIDFD ` constant.
4630+
4631+
4632+ .. data :: WCONTINUED
4633+
4634+ This *options * flag for :func: `waitpid `, :func: `wait3 `, :func: `wait4 `, and
4635+ :func: `waitid ` causes child processes to be reported if they have been
4636+ continued from a job control stop since they were last reported.
4637+
4638+ .. availability :: Unix, not Emscripten, not WASI.
4639+
4640+
4641+ .. data :: WEXITED
4642+
4643+ This *options * flag for :func: `waitid ` causes child processes that have terminated to
4644+ be reported.
4645+
4646+ The other ``wait* `` functions always report children that have terminated,
4647+ so this option is not available for them.
4648+
4649+ .. availability :: Unix, not Emscripten, not WASI.
4650+
4651+ .. versionadded :: 3.3
4652+
4653+
4654+ .. data :: WSTOPPED
4655+
4656+ This *options * flag for :func: `waitid ` causes child processes that have been stopped
4657+ by the delivery of a signal to be reported.
4658+
4659+ This option is not available for the other ``wait* `` functions.
4660+
4661+ .. availability :: Unix, not Emscripten, not WASI.
4662+
4663+ .. versionadded :: 3.3
4664+
4665+
4666+ .. data :: WUNTRACED
4667+
4668+ This *options * flag for :func: `waitpid `, :func: `wait3 `, and :func: `wait4 ` causes
4669+ child processes to also be reported if they have been stopped but their
4670+ current state has not been reported since they were stopped.
4671+
4672+ This option is not available for :func: `waitid `.
4673+
4674+ .. availability :: Unix, not Emscripten, not WASI.
4675+
4676+
4677+ .. data :: WNOHANG
4678+
4679+ This *options * flag causes :func: `waitpid `, :func: `wait3 `, :func: `wait4 `, and
4680+ :func: `waitid ` to return right away if no child process status is available
4681+ immediately.
4682+
4683+ .. availability :: Unix, not Emscripten, not WASI.
4684+
4685+
4686+ .. data :: WNOWAIT
4687+
4688+ This *options * flag causes :func: `waitid ` to leave the child in a waitable state, so that
4689+ a later :func: `!wait* ` call can be used to retrieve the child status information again.
4690+
4691+ This option is not available for the other ``wait* `` functions.
4692+
4693+ .. availability :: Unix, not Emscripten, not WASI.
4694+
4695+
4696+ .. data :: CLD_EXITED
4697+ CLD_KILLED
4698+ CLD_DUMPED
4699+ CLD_TRAPPED
4700+ CLD_STOPPED
4701+ CLD_CONTINUED
4702+
4703+ These are the possible values for :attr: `!si_code ` in the result returned by
4704+ :func: `waitid `.
4705+
4706+ .. availability :: Unix, not Emscripten, not WASI.
4707+
4708+ .. versionadded :: 3.3
4709+
4710+ .. versionchanged :: 3.9
4711+ Added :data: `CLD_KILLED ` and :data: `CLD_STOPPED ` values.
4712+
4713+
46394714.. function :: waitstatus_to_exitcode(status)
46404715
46414716 Convert a wait status to an exit code.
@@ -4668,32 +4743,6 @@ written in Python, such as a mail server's external command delivery program.
46684743 .. versionadded :: 3.9
46694744
46704745
4671- .. data :: WNOHANG
4672-
4673- The option for :func: `waitpid ` to return immediately if no child process status
4674- is available immediately. The function returns ``(0, 0) `` in this case.
4675-
4676- .. availability :: Unix, not Emscripten, not WASI.
4677-
4678-
4679- .. data :: WCONTINUED
4680-
4681- This option causes child processes to be reported if they have been continued
4682- from a job control stop since their status was last reported.
4683-
4684- .. availability :: Unix, not Emscripten, not WASI.
4685-
4686- Some Unix systems.
4687-
4688-
4689- .. data :: WUNTRACED
4690-
4691- This option causes child processes to be reported if they have been stopped but
4692- their current state has not been reported since they were stopped.
4693-
4694- .. availability :: Unix, not Emscripten, not WASI.
4695-
4696-
46974746The following functions take a process status code as returned by
46984747:func: `system `, :func: `wait `, or :func: `waitpid ` as a parameter. They may be
46994748used to determine the disposition of a process.
0 commit comments