Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
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
5 changes: 4 additions & 1 deletion 5 Doc/library/test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -831,12 +831,15 @@ The :mod:`test.support` module defines the following functions:
*exitcode*.

Raise an :exc:`AssertionError` if the process exit code is not equal to
*exitcode*.
*exitcode*. Use ``exitcode=None`` to not check the process exit code. The
returned process exit code can be used to check it in the caller.

If the process runs longer than *timeout* seconds (:data:`SHORT_TIMEOUT` by
default), kill the process and raise an :exc:`AssertionError`. The timeout
feature is not available on Windows.

Return the process exit code.

.. versionadded:: 3.9


Expand Down
16 changes: 11 additions & 5 deletions 16 Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3407,11 +3407,15 @@ def wait_process(pid, *, exitcode, timeout=None):
Wait until process pid completes and check that the process exit code is
exitcode.

Raise an AssertionError if the process exit code is not equal to exitcode.
Raise an AssertionError if the process exit code is not equal to
exitcode. Use exitcode=None to not check the process exit code. The
returned process exit code can be used to check it in the caller.

If the process runs longer than timeout seconds (SHORT_TIMEOUT by default),
kill the process (if signal.SIGKILL is available) and raise an
AssertionError. The timeout feature is not available on Windows.
If the process runs longer than *timeout* seconds (SHORT_TIMEOUT by
default), kill the process and raise an AssertionError. The timeout feature
is not available on Windows.

Return the process exit code.
"""
if os.name != "nt":
import signal
Expand Down Expand Up @@ -3447,10 +3451,12 @@ def wait_process(pid, *, exitcode, timeout=None):
pid2, status = os.waitpid(pid, 0)

exitcode2 = os.waitstatus_to_exitcode(status)
if exitcode2 != exitcode:
if exitcode is not None and exitcode2 != exitcode:
raise AssertionError(f"process {pid} exited with code {exitcode2}, "
f"but exit code {exitcode} is expected")

# sanity check: it should not fail in practice
if pid2 != pid:
raise AssertionError(f"pid {pid2} != pid {pid}")

return exitcode2
12 changes: 7 additions & 5 deletions 12 Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,13 +1893,15 @@ def run_child(self, child, terminal_input):
self.fail("got %d lines in pipe but expected 2, child output was:\n%s"
% (len(lines), child_output))

# Wait until the child process completes before closing the PTY to
# prevent sending SIGHUP to the child process.
support.wait_process(pid, exitcode=0)

# Close the PTY
# bpo-40140, bpo-40155: Close the PTY before waiting for the child
# process completion, otherwise the child process blocks on AIX
# and Solaris.
os.close(fd)

# The child process can be terminated by SIGHUP when the PTY is closed
exitcode = support.wait_process(pid, exitcode=None)
self.assertIn(exitcode, (0, -signal.SIGHUP))

return lines

def check_input_tty(self, prompt, terminal_input, stdio_encoding=None):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.