@@ -4491,83 +4491,50 @@ written in Python, such as a mail server's external command delivery program.
4491
4491
number is zero); the high bit of the low byte is set if a core file was
4492
4492
produced.
4493
4493
4494
+ If there are no children that could be waited for, :exc: `ChildProcessError `
4495
+ is raised.
4496
+
4494
4497
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4495
4498
exit code.
4496
4499
4497
4500
.. availability :: Unix, not Emscripten, not WASI.
4498
4501
4499
4502
.. seealso ::
4500
4503
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.
4503
4507
4504
- .. function :: waitid(idtype, id, options, /)
4505
4508
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, /)
4545
4510
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.
4548
4512
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.
4550
4515
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.
4552
4519
4520
+ The return value is an object representing the data contained in the
4521
+ :c:type: `!siginfo_t ` structure with the following attributes:
4553
4522
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)
4560
4528
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.
4563
4533
4564
4534
.. availability :: Unix, not Emscripten, not WASI.
4565
4535
4566
4536
.. versionadded :: 3.3
4567
4537
4568
- .. versionchanged :: 3.9
4569
- Added :data: `CLD_KILLED ` and :data: `CLD_STOPPED ` values.
4570
-
4571
4538
4572
4539
.. function :: waitpid(pid, options, /)
4573
4540
@@ -4585,8 +4552,11 @@ written in Python, such as a mail server's external command delivery program.
4585
4552
``-1 ``, status is requested for any process in the process group ``-pid `` (the
4586
4553
absolute value of *pid *).
4587
4554
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 `.
4590
4560
4591
4561
On Windows: Wait for completion of a process given by process handle *pid *, and
4592
4562
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.
4599
4569
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4600
4570
exit code.
4601
4571
4602
- .. availability :: Unix, not Emscripten, not WASI.
4572
+ .. availability :: Unix, Windows, not Emscripten, not WASI.
4603
4573
4604
4574
.. versionchanged :: 3.5
4605
4575
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.
4612
4582
Similar to :func: `waitpid `, except no process id argument is given and a
4613
4583
3-element tuple containing the child's process id, exit status indication,
4614
4584
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 `.
4618
4588
4619
4589
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4620
4590
exitcode.
@@ -4625,17 +4595,122 @@ written in Python, such as a mail server's external command delivery program.
4625
4595
.. function :: wait4(pid, options)
4626
4596
4627
4597
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 `.
4632
4602
4633
4603
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4634
4604
exitcode.
4635
4605
4636
4606
.. availability :: Unix, not Emscripten, not WASI.
4637
4607
4638
4608
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
+
4639
4714
.. function :: waitstatus_to_exitcode(status)
4640
4715
4641
4716
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.
4668
4743
.. versionadded :: 3.9
4669
4744
4670
4745
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
-
4697
4746
The following functions take a process status code as returned by
4698
4747
:func: `system `, :func: `wait `, or :func: `waitpid ` as a parameter. They may be
4699
4748
used to determine the disposition of a process.
0 commit comments