mirror of
https://github.com/python/cpython
synced 2024-10-14 15:09:02 +00:00
pty.spawn() now returns the child process status as returned by os.waitpid().
Addresses the remaining feature request from issue #2489.
This commit is contained in:
parent
b32d5912d2
commit
0f21adf799
|
@ -45,6 +45,9 @@ The :mod:`pty` module defines the following functions:
|
||||||
a file descriptor. The defaults try to read 1024 bytes each time they are
|
a file descriptor. The defaults try to read 1024 bytes each time they are
|
||||||
called.
|
called.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.4
|
||||||
|
:func:`spawn` now returns the status value from :func:`os.waitpid`
|
||||||
|
on the child process.
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
|
|
@ -178,3 +178,4 @@ def spawn(argv, master_read=_read, stdin_read=_read):
|
||||||
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
|
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
|
||||||
|
|
||||||
os.close(master_fd)
|
os.close(master_fd)
|
||||||
|
return os.waitpid(pid, 0)[1]
|
||||||
|
|
|
@ -196,6 +196,12 @@ def test_fork(self):
|
||||||
|
|
||||||
# pty.fork() passed.
|
# pty.fork() passed.
|
||||||
|
|
||||||
|
def test_spawn_returns_status(self):
|
||||||
|
status = pty.spawn([sys.executable, '-c', 'import sys; sys.exit(0)'])
|
||||||
|
self.assertEqual(status, 0)
|
||||||
|
status = pty.spawn([sys.executable, '-c', 'import sys; sys.exit(5)'])
|
||||||
|
self.assertEqual(status, 5 << 8)
|
||||||
|
|
||||||
|
|
||||||
class SmallPtyTests(unittest.TestCase):
|
class SmallPtyTests(unittest.TestCase):
|
||||||
"""These tests don't spawn children or hang."""
|
"""These tests don't spawn children or hang."""
|
||||||
|
|
|
@ -15,6 +15,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- pty.spawn() now returns the child process status returned by os.waitpid().
|
||||||
|
|
||||||
- Issue #15756: subprocess.poll() now properly handles errno.ECHILD to
|
- Issue #15756: subprocess.poll() now properly handles errno.ECHILD to
|
||||||
return a returncode of 0 when the child has already exited or cannot
|
return a returncode of 0 when the child has already exited or cannot
|
||||||
be waited on.
|
be waited on.
|
||||||
|
|
Loading…
Reference in a new issue