]> granicus.if.org Git - python/commitdiff
pty.spawn() now returns the child process status as returned by os.waitpid().
authorGregory P. Smith <greg@krypto.org>
Sat, 29 Sep 2012 19:41:03 +0000 (12:41 -0700)
committerGregory P. Smith <greg@krypto.org>
Sat, 29 Sep 2012 19:41:03 +0000 (12:41 -0700)
Addresses the remaining feature request from issue #2489.

Doc/library/pty.rst
Lib/pty.py
Lib/test/test_pty.py
Misc/NEWS

index 2b9385b5f9e9677d9605c564875c1d4d37ac214e..90baec542feaf60e81443ce41ade0d225fa33091 100644 (file)
@@ -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
    called.
 
+   .. versionchanged:: 3.4
+      :func:`spawn` now returns the status value from :func:`os.waitpid`
+      on the child process.
 
 Example
 -------
index 3ccf619896c917f6b8944d819c03627091fb14a8..3b79202199ee0a7aaf06439a92c6b6e5451a78c2 100644 (file)
@@ -178,3 +178,4 @@ def spawn(argv, master_read=_read, stdin_read=_read):
             tty.tcsetattr(STDIN_FILENO, tty.TCSAFLUSH, mode)
 
     os.close(master_fd)
+    return os.waitpid(pid, 0)[1]
index ef95268e19e593012a1e6be5a2e922cb73cbf9e7..db370391f78462392877aa2685afbffe93708b2f 100644 (file)
@@ -196,6 +196,12 @@ class PtyTest(unittest.TestCase):
 
         # 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."""
index 0012f1ea66957e877c8d01e3a12c67efc4fad886..04751b710b1aeddbe9f5ef6a23111e00a1956f59 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@ Core and Builtins
 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.