[Python-checkins] cpython: pty.spawn() now returns the child process status as returned by os.waitpid().
gregory.p.smith
python-checkins at python.org
Sat Sep 29 21:41:11 CEST 2012
http://hg.python.org/cpython/rev/ec2921d4de37
changeset: 79282:ec2921d4de37
user: Gregory P. Smith <greg at krypto.org>
date: Sat Sep 29 12:41:03 2012 -0700
summary:
pty.spawn() now returns the child process status as returned by os.waitpid().
Addresses the remaining feature request from issue #2489.
files:
Doc/library/pty.rst | 3 +++
Lib/pty.py | 1 +
Lib/test/test_pty.py | 6 ++++++
Misc/NEWS | 2 ++
4 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/Doc/library/pty.rst b/Doc/library/pty.rst
--- a/Doc/library/pty.rst
+++ b/Doc/library/pty.rst
@@ -45,6 +45,9 @@
a file descriptor. The defaults try to read 1024 bytes each time they are
called.
+ .. versionchanged:: 3.4
+ :func:`spawn` now returns the status value from :func:`os.waitpid`
+ on the child process.
Example
-------
diff --git a/Lib/pty.py b/Lib/pty.py
--- a/Lib/pty.py
+++ b/Lib/pty.py
@@ -178,3 +178,4 @@
tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
os.close(master_fd)
+ return os.waitpid(pid, 0)[1]
diff --git a/Lib/test/test_pty.py b/Lib/test/test_pty.py
--- a/Lib/test/test_pty.py
+++ b/Lib/test/test_pty.py
@@ -196,6 +196,12 @@
# 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):
"""These tests don't spawn children or hang."""
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@
Library
-------
+- pty.spawn() now returns the child process status returned by os.waitpid().
+
- Issue #15756: subprocess.poll() now properly handles errno.ECHILD to
return a returncode of 0 when the child has already exited or cannot
be waited on.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list