From b79eb0502c5a01d4ebf793d689f6cc5fa35a1ed5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 3 Feb 2014 23:08:14 +0100 Subject: asyncio.subprocess: Replace Process.get_subprocess() method with a Process.subprocess read-only property --- Doc/library/asyncio-subprocess.rst | 34 ++++++++++++++++---------------- Lib/asyncio/subprocess.py | 3 ++- Lib/test/test_asyncio/test_subprocess.py | 18 ++++++++--------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/Doc/library/asyncio-subprocess.rst b/Doc/library/asyncio-subprocess.rst index 4c399c6..5bfbbc7 100644 --- a/Doc/library/asyncio-subprocess.rst +++ b/Doc/library/asyncio-subprocess.rst @@ -57,6 +57,21 @@ Process .. class:: asyncio.subprocess.Process + .. attribute:: pid + + The identifier of the process. + + Note that if you set the *shell* argument to ``True``, this is the + process identifier of the spawned shell. + + .. attribute:: returncode + + Return code of the process when it exited. A ``None`` value indicates + that the process has not terminated yet. + + A negative value ``-N`` indicates that the child was terminated by signal + ``N`` (Unix only). + .. attribute:: stdin Standard input stream (write), ``None`` if the process was created with @@ -72,20 +87,9 @@ Process Standard error stream (read), ``None`` if the process was created with ``stderr=None``. - .. attribute:: pid - - The identifier of the process. - - Note that if you set the *shell* argument to ``True``, this is the - process identifier of the spawned shell. + .. attribute:: subprocess - .. attribute:: returncode - - Return code of the process when it exited. A ``None`` value indicates - that the process has not terminated yet. - - A negative value ``-N`` indicates that the child was terminated by signal - ``N`` (Unix only). + Underlying :class:`subprocess.Popen` object. .. method:: communicate(input=None) @@ -107,10 +111,6 @@ Process The data read is buffered in memory, so do not use this method if the data size is large or unlimited. - .. method:: get_subprocess() - - Get the underlying :class:`subprocess.Popen` object. - .. method:: kill() Kills the child. On Posix OSs the function sends :py:data:`SIGKILL` to diff --git a/Lib/asyncio/subprocess.py b/Lib/asyncio/subprocess.py index 4312d44..3047894 100644 --- a/Lib/asyncio/subprocess.py +++ b/Lib/asyncio/subprocess.py @@ -106,7 +106,8 @@ class Process: yield from waiter return waiter.result() - def get_subprocess(self): + @property + def subprocess(self): return self._transport.get_extra_info('subprocess') def _check_alive(self): diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index 4f38cc7..785156c 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -119,7 +119,7 @@ class SubprocessMixin: returncode = self.loop.run_until_complete(proc.wait()) self.assertEqual(-signal.SIGHUP, returncode) - def test_get_subprocess(self): + def test_subprocess(self): args = PROGRAM_EXIT_FAST @asyncio.coroutine @@ -127,14 +127,14 @@ class SubprocessMixin: proc = yield from asyncio.create_subprocess_exec(*args, loop=self.loop) yield from proc.wait() - - popen = proc.get_subprocess() - popen.wait() - return (proc, popen) - - proc, popen = self.loop.run_until_complete(run()) - self.assertEqual(popen.returncode, proc.returncode) - self.assertEqual(popen.pid, proc.pid) + # need to poll subprocess.Popen, otherwise the returncode + # attribute is not set + proc.subprocess.wait() + return proc + + proc = self.loop.run_until_complete(run()) + self.assertEqual(proc.subprocess.returncode, proc.returncode) + self.assertEqual(proc.subprocess.pid, proc.pid) def test_broken_pipe(self): large_data = b'x' * support.PIPE_MAX_SIZE -- cgit v0.12