@@ -4376,83 +4376,50 @@ written in Python, such as a mail server's external command delivery program.
4376
4376
number is zero); the high bit of the low byte is set if a core file was
4377
4377
produced.
4378
4378
4379
+ If there are no children that could be waited for, :exc: `ChildProcessError `
4380
+ is raised.
4381
+
4379
4382
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4380
4383
exit code.
4381
4384
4382
4385
.. availability :: Unix, not Emscripten, not WASI.
4383
4386
4384
4387
.. seealso ::
4385
4388
4386
- :func: `waitpid ` can be used to wait for the completion of a specific
4387
- child process and has more options.
4389
+ The other :func: `!wait* ` functions documented below can be used to wait for the
4390
+ completion of a specific child process and have more options.
4391
+ :func: `waitpid ` is the only one also available on Windows.
4388
4392
4389
- .. function :: waitid(idtype, id, options, /)
4390
4393
4391
- Wait for the completion of one or more child processes.
4392
- *idtype * can be :data: `P_PID `, :data: `P_PGID `, :data: `P_ALL `, or
4393
- :data: `P_PIDFD ` on Linux.
4394
- *id * specifies the pid to wait on.
4395
- *options * is constructed from the ORing of one or more of :data: `WEXITED `,
4396
- :data: `WSTOPPED ` or :data: `WCONTINUED ` and additionally may be ORed with
4397
- :data: `WNOHANG ` or :data: `WNOWAIT `. The return value is an object
4398
- representing the data contained in the :c:type: `siginfo_t ` structure, namely:
4399
- :attr: `si_pid `, :attr: `si_uid `, :attr: `si_signo `, :attr: `si_status `,
4400
- :attr: `si_code ` or ``None `` if :data: `WNOHANG ` is specified and there are no
4401
- children in a waitable state.
4402
-
4403
- .. availability :: Unix, not Emscripten, not WASI.
4404
-
4405
- .. versionadded :: 3.3
4406
-
4407
- .. data :: P_PID
4408
- P_PGID
4409
- P_ALL
4410
-
4411
- These are the possible values for *idtype * in :func: `waitid `. They affect
4412
- how *id * is interpreted.
4413
-
4414
- .. availability :: Unix, not Emscripten, not WASI.
4415
-
4416
- .. versionadded :: 3.3
4417
-
4418
- .. data :: P_PIDFD
4419
-
4420
- This is a Linux-specific *idtype * that indicates that *id * is a file
4421
- descriptor that refers to a process.
4422
-
4423
- .. availability :: Linux >= 5.4
4424
-
4425
- .. versionadded :: 3.9
4426
-
4427
- .. data :: WEXITED
4428
- WSTOPPED
4429
- WNOWAIT
4394
+ .. function :: waitid(idtype, id, options, /)
4430
4395
4431
- Flags that can be used in *options * in :func: `waitid ` that specify what
4432
- child signal to wait for.
4396
+ Wait for the completion of a child process.
4433
4397
4434
- .. availability :: Unix, not Emscripten, not WASI.
4398
+ *idtype * can be :data: `P_PID `, :data: `P_PGID `, :data: `P_ALL `, or (on Linux) :data: `P_PIDFD `.
4399
+ The interpretation of *id * depends on it; see their individual descriptions.
4435
4400
4436
- .. versionadded :: 3.3
4401
+ *options * is an OR combination of flags. At least one of :data: `WEXITED `,
4402
+ :data: `WSTOPPED ` or :data: `WCONTINUED ` is required;
4403
+ :data: `WNOHANG ` and :data: `WNOWAIT ` are additional optional flags.
4437
4404
4405
+ The return value is an object representing the data contained in the
4406
+ :c:type: `!siginfo_t ` structure with the following attributes:
4438
4407
4439
- .. data :: CLD_EXITED
4440
- CLD_KILLED
4441
- CLD_DUMPED
4442
- CLD_TRAPPED
4443
- CLD_STOPPED
4444
- CLD_CONTINUED
4408
+ * :attr: `!si_pid ` (process ID)
4409
+ * :attr: `!si_uid ` (real user ID of the child)
4410
+ * :attr: `!si_signo ` (always :data: `~signal.SIGCHLD `)
4411
+ * :attr: `!si_status ` (the exit status or signal number, depending on :attr: `!si_code `)
4412
+ * :attr: `!si_code ` (see :data: `CLD_EXITED ` for possible values)
4445
4413
4446
- These are the possible values for :attr: `si_code ` in the result returned by
4447
- :func: `waitid `.
4414
+ If :data: `WNOHANG ` is specified and there are no matching children in the
4415
+ requested state, ``None `` is returned.
4416
+ Otherwise, if there are no matching children
4417
+ that could be waited for, :exc: `ChildProcessError ` is raised.
4448
4418
4449
4419
.. availability :: Unix, not Emscripten, not WASI.
4450
4420
4451
4421
.. versionadded :: 3.3
4452
4422
4453
- .. versionchanged :: 3.9
4454
- Added :data: `CLD_KILLED ` and :data: `CLD_STOPPED ` values.
4455
-
4456
4423
4457
4424
.. function :: waitpid(pid, options, /)
4458
4425
@@ -4470,8 +4437,11 @@ written in Python, such as a mail server's external command delivery program.
4470
4437
``-1 ``, status is requested for any process in the process group ``-pid `` (the
4471
4438
absolute value of *pid *).
4472
4439
4473
- An :exc: `OSError ` is raised with the value of errno when the syscall
4474
- returns -1.
4440
+ *options * is an OR combination of flags. If it contains :data: `WNOHANG ` and
4441
+ there are no matching children in the requested state, ``(0, 0) `` is
4442
+ returned. Otherwise, if there are no matching children that could be waited
4443
+ for, :exc: `ChildProcessError ` is raised. Other options that can be used are
4444
+ :data: `WUNTRACED ` and :data: `WCONTINUED `.
4475
4445
4476
4446
On Windows: Wait for completion of a process given by process handle *pid *, and
4477
4447
return a tuple containing *pid *, and its exit status shifted left by 8 bits
@@ -4484,7 +4454,7 @@ written in Python, such as a mail server's external command delivery program.
4484
4454
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4485
4455
exit code.
4486
4456
4487
- .. availability :: Unix, not Emscripten, not WASI.
4457
+ .. availability :: Unix, Windows, not Emscripten, not WASI.
4488
4458
4489
4459
.. versionchanged :: 3.5
4490
4460
If the system call is interrupted and the signal handler does not raise an
@@ -4497,9 +4467,9 @@ written in Python, such as a mail server's external command delivery program.
4497
4467
Similar to :func: `waitpid `, except no process id argument is given and a
4498
4468
3-element tuple containing the child's process id, exit status indication,
4499
4469
and resource usage information is returned. Refer to
4500
- :mod: ` resource `. \ : func: `~ resource.getrusage ` for details on resource usage
4501
- information. The option argument is the same as that provided to
4502
- :func: `waitpid ` and :func: ` wait4 `.
4470
+ :func: `resource.getrusage ` for details on resource usage information. The
4471
+ * options * argument is the same as that provided to :func: ` waitpid ` and
4472
+ :func: `wait4 `.
4503
4473
4504
4474
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4505
4475
exitcode.
@@ -4510,17 +4480,122 @@ written in Python, such as a mail server's external command delivery program.
4510
4480
.. function :: wait4(pid, options)
4511
4481
4512
4482
Similar to :func: `waitpid `, except a 3-element tuple, containing the child's
4513
- process id, exit status indication, and resource usage information is returned.
4514
- Refer to :mod: ` resource `. \ : func: `~ resource.getrusage ` for details on
4515
- resource usage information. The arguments to :func: `wait4 ` are the same
4516
- as those provided to :func: `waitpid `.
4483
+ process id, exit status indication, and resource usage information is
4484
+ returned. Refer to :func: `resource.getrusage ` for details on resource usage
4485
+ information. The arguments to :func: `wait4 ` are the same as those provided
4486
+ to :func: `waitpid `.
4517
4487
4518
4488
:func: `waitstatus_to_exitcode ` can be used to convert the exit status into an
4519
4489
exitcode.
4520
4490
4521
4491
.. availability :: Unix, not Emscripten, not WASI.
4522
4492
4523
4493
4494
+ .. data :: P_PID
4495
+ P_PGID
4496
+ P_ALL
4497
+ P_PIDFD
4498
+
4499
+ These are the possible values for *idtype * in :func: `waitid `. They affect
4500
+ how *id * is interpreted:
4501
+
4502
+ * :data: `!P_PID ` - wait for the child whose PID is *id *.
4503
+ * :data: `!P_PGID ` - wait for any child whose progress group ID is *id *.
4504
+ * :data: `!P_ALL ` - wait for any child; *id * is ignored.
4505
+ * :data: `!P_PIDFD ` - wait for the child identified by the file descriptor
4506
+ *id * (a process file descriptor created with :func: `pidfd_open `).
4507
+
4508
+ .. availability :: Unix, not Emscripten, not WASI.
4509
+
4510
+ .. note :: :data:`!P_PIDFD` is only available on Linux >= 5.4.
4511
+
4512
+ .. versionadded :: 3.3
4513
+ .. versionadded :: 3.9
4514
+ The :data: `!P_PIDFD ` constant.
4515
+
4516
+
4517
+ .. data :: WCONTINUED
4518
+
4519
+ This *options * flag for :func: `waitpid `, :func: `wait3 `, :func: `wait4 `, and
4520
+ :func: `waitid ` causes child processes to be reported if they have been
4521
+ continued from a job control stop since they were last reported.
4522
+
4523
+ .. availability :: Unix, not Emscripten, not WASI.
4524
+
4525
+
4526
+ .. data :: WEXITED
4527
+
4528
+ This *options * flag for :func: `waitid ` causes child processes that have terminated to
4529
+ be reported.
4530
+
4531
+ The other ``wait* `` functions always report children that have terminated,
4532
+ so this option is not available for them.
4533
+
4534
+ .. availability :: Unix, not Emscripten, not WASI.
4535
+
4536
+ .. versionadded :: 3.3
4537
+
4538
+
4539
+ .. data :: WSTOPPED
4540
+
4541
+ This *options * flag for :func: `waitid ` causes child processes that have been stopped
4542
+ by the delivery of a signal to be reported.
4543
+
4544
+ This option is not available for the other ``wait* `` functions.
4545
+
4546
+ .. availability :: Unix, not Emscripten, not WASI.
4547
+
4548
+ .. versionadded :: 3.3
4549
+
4550
+
4551
+ .. data :: WUNTRACED
4552
+
4553
+ This *options * flag for :func: `waitpid `, :func: `wait3 `, and :func: `wait4 ` causes
4554
+ child processes to also be reported if they have been stopped but their
4555
+ current state has not been reported since they were stopped.
4556
+
4557
+ This option is not available for :func: `waitid `.
4558
+
4559
+ .. availability :: Unix, not Emscripten, not WASI.
4560
+
4561
+
4562
+ .. data :: WNOHANG
4563
+
4564
+ This *options * flag causes :func: `waitpid `, :func: `wait3 `, :func: `wait4 `, and
4565
+ :func: `waitid ` to return right away if no child process status is available
4566
+ immediately.
4567
+
4568
+ .. availability :: Unix, not Emscripten, not WASI.
4569
+
4570
+
4571
+ .. data :: WNOWAIT
4572
+
4573
+ This *options * flag causes :func: `waitid ` to leave the child in a waitable state, so that
4574
+ a later :func: `!wait* ` call can be used to retrieve the child status information again.
4575
+
4576
+ This option is not available for the other ``wait* `` functions.
4577
+
4578
+ .. availability :: Unix, not Emscripten, not WASI.
4579
+
4580
+
4581
+ .. data :: CLD_EXITED
4582
+ CLD_KILLED
4583
+ CLD_DUMPED
4584
+ CLD_TRAPPED
4585
+ CLD_STOPPED
4586
+ CLD_CONTINUED
4587
+
4588
+ These are the possible values for :attr: `!si_code ` in the result returned by
4589
+ :func: `waitid `.
4590
+
4591
+ .. availability :: Unix, not Emscripten, not WASI.
4592
+
4593
+ .. versionadded :: 3.3
4594
+
4595
+ .. versionchanged :: 3.9
4596
+ Added :data: `CLD_KILLED ` and :data: `CLD_STOPPED ` values.
4597
+
4598
+
4524
4599
.. function :: waitstatus_to_exitcode(status)
4525
4600
4526
4601
Convert a wait status to an exit code.
@@ -4553,32 +4628,6 @@ written in Python, such as a mail server's external command delivery program.
4553
4628
.. versionadded :: 3.9
4554
4629
4555
4630
4556
- .. data :: WNOHANG
4557
-
4558
- The option for :func: `waitpid ` to return immediately if no child process status
4559
- is available immediately. The function returns ``(0, 0) `` in this case.
4560
-
4561
- .. availability :: Unix, not Emscripten, not WASI.
4562
-
4563
-
4564
- .. data :: WCONTINUED
4565
-
4566
- This option causes child processes to be reported if they have been continued
4567
- from a job control stop since their status was last reported.
4568
-
4569
- .. availability :: Unix, not Emscripten, not WASI.
4570
-
4571
- Some Unix systems.
4572
-
4573
-
4574
- .. data :: WUNTRACED
4575
-
4576
- This option causes child processes to be reported if they have been stopped but
4577
- their current state has not been reported since they were stopped.
4578
-
4579
- .. availability :: Unix, not Emscripten, not WASI.
4580
-
4581
-
4582
4631
The following functions take a process status code as returned by
4583
4632
:func: `system `, :func: `wait `, or :func: `waitpid ` as a parameter. They may be
4584
4633
used to determine the disposition of a process.
0 commit comments