diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2017-12-11 15:35:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-11 15:35:49 (GMT) |
commit | 8874342cf332c3aa3d845155cc4b41b00c2d9e9d (patch) | |
tree | 79b2b2a3413fde605670e995428e64144a509f77 /Doc/library/asyncio-subprocess.rst | |
parent | abae67ebc2897ca37df067f322d19e19d1ef6d88 (diff) | |
download | cpython-8874342cf332c3aa3d845155cc4b41b00c2d9e9d.zip cpython-8874342cf332c3aa3d845155cc4b41b00c2d9e9d.tar.gz cpython-8874342cf332c3aa3d845155cc4b41b00c2d9e9d.tar.bz2 |
bpo-32258: Replace 'yield from' to 'await' in asyncio docs (#4779)
* Replace 'yield from' to 'await' in asyncio docs
* Fix docstrings
Diffstat (limited to 'Doc/library/asyncio-subprocess.rst')
-rw-r--r-- | Doc/library/asyncio-subprocess.rst | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/Doc/library/asyncio-subprocess.rst b/Doc/library/asyncio-subprocess.rst index 1c1d0be..280b764 100644 --- a/Doc/library/asyncio-subprocess.rst +++ b/Doc/library/asyncio-subprocess.rst @@ -347,21 +347,20 @@ wait for the subprocess exit. The subprocess is created by the def process_exited(self): self.exit_future.set_result(True) - @asyncio.coroutine - def get_date(loop): + async def get_date(loop): code = 'import datetime; print(datetime.datetime.now())' exit_future = asyncio.Future(loop=loop) # Create the subprocess controlled by the protocol DateProtocol, # redirect the standard output into a pipe - create = loop.subprocess_exec(lambda: DateProtocol(exit_future), - sys.executable, '-c', code, - stdin=None, stderr=None) - transport, protocol = yield from create + transport, protocol = await loop.subprocess_exec( + lambda: DateProtocol(exit_future), + sys.executable, '-c', code, + stdin=None, stderr=None) # Wait for the subprocess exit using the process_exited() method # of the protocol - yield from exit_future + await exit_future # Close the stdout pipe transport.close() @@ -398,16 +397,16 @@ function:: code = 'import datetime; print(datetime.datetime.now())' # Create the subprocess, redirect the standard output into a pipe - create = asyncio.create_subprocess_exec(sys.executable, '-c', code, - stdout=asyncio.subprocess.PIPE) - proc = yield from create + proc = await asyncio.create_subprocess_exec( + sys.executable, '-c', code, + stdout=asyncio.subprocess.PIPE) # Read one line of output - data = yield from proc.stdout.readline() + data = await proc.stdout.readline() line = data.decode('ascii').rstrip() # Wait for the subprocess exit - yield from proc.wait() + await proc.wait() return line if sys.platform == "win32": |