Commit b79eb050 authored by Victor Stinner's avatar Victor Stinner

asyncio.subprocess: Replace Process.get_subprocess() method with a

Process.subprocess read-only property
parent cb306d1b
...@@ -57,6 +57,21 @@ Process ...@@ -57,6 +57,21 @@ Process
.. class:: asyncio.subprocess.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 .. attribute:: stdin
Standard input stream (write), ``None`` if the process was created with Standard input stream (write), ``None`` if the process was created with
...@@ -72,20 +87,9 @@ Process ...@@ -72,20 +87,9 @@ Process
Standard error stream (read), ``None`` if the process was created with Standard error stream (read), ``None`` if the process was created with
``stderr=None``. ``stderr=None``.
.. attribute:: pid .. attribute:: subprocess
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 Underlying :class:`subprocess.Popen` object.
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).
.. method:: communicate(input=None) .. method:: communicate(input=None)
...@@ -107,10 +111,6 @@ Process ...@@ -107,10 +111,6 @@ Process
The data read is buffered in memory, so do not use this method if the The data read is buffered in memory, so do not use this method if the
data size is large or unlimited. data size is large or unlimited.
.. method:: get_subprocess()
Get the underlying :class:`subprocess.Popen` object.
.. method:: kill() .. method:: kill()
Kills the child. On Posix OSs the function sends :py:data:`SIGKILL` to Kills the child. On Posix OSs the function sends :py:data:`SIGKILL` to
......
...@@ -106,7 +106,8 @@ class Process: ...@@ -106,7 +106,8 @@ class Process:
yield from waiter yield from waiter
return waiter.result() return waiter.result()
def get_subprocess(self): @property
def subprocess(self):
return self._transport.get_extra_info('subprocess') return self._transport.get_extra_info('subprocess')
def _check_alive(self): def _check_alive(self):
......
...@@ -119,7 +119,7 @@ class SubprocessMixin: ...@@ -119,7 +119,7 @@ class SubprocessMixin:
returncode = self.loop.run_until_complete(proc.wait()) returncode = self.loop.run_until_complete(proc.wait())
self.assertEqual(-signal.SIGHUP, returncode) self.assertEqual(-signal.SIGHUP, returncode)
def test_get_subprocess(self): def test_subprocess(self):
args = PROGRAM_EXIT_FAST args = PROGRAM_EXIT_FAST
@asyncio.coroutine @asyncio.coroutine
...@@ -127,14 +127,14 @@ class SubprocessMixin: ...@@ -127,14 +127,14 @@ class SubprocessMixin:
proc = yield from asyncio.create_subprocess_exec(*args, proc = yield from asyncio.create_subprocess_exec(*args,
loop=self.loop) loop=self.loop)
yield from proc.wait() yield from proc.wait()
# need to poll subprocess.Popen, otherwise the returncode
popen = proc.get_subprocess() # attribute is not set
popen.wait() proc.subprocess.wait()
return (proc, popen) return proc
proc, popen = self.loop.run_until_complete(run()) proc = self.loop.run_until_complete(run())
self.assertEqual(popen.returncode, proc.returncode) self.assertEqual(proc.subprocess.returncode, proc.returncode)
self.assertEqual(popen.pid, proc.pid) self.assertEqual(proc.subprocess.pid, proc.pid)
def test_broken_pipe(self): def test_broken_pipe(self):
large_data = b'x' * support.PIPE_MAX_SIZE large_data = b'x' * support.PIPE_MAX_SIZE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment