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 /Lib/asyncio/locks.py | |
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 'Lib/asyncio/locks.py')
-rw-r--r-- | Lib/asyncio/locks.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py index 54f6258..6193837 100644 --- a/Lib/asyncio/locks.py +++ b/Lib/asyncio/locks.py @@ -23,6 +23,10 @@ class _ContextManager: with lock: <block> + + Deprecated, use 'async with' statement: + async with lock: + <block> """ def __init__(self, lock): @@ -64,6 +68,9 @@ class _ContextManagerMixin: # <block> # finally: # lock.release() + # Deprecated, use 'async with' statement: + # async with lock: + # <block> warnings.warn("'with (yield from lock)' is deprecated " "use 'async with lock' instead", DeprecationWarning, stacklevel=2) @@ -113,16 +120,16 @@ class Lock(_ContextManagerMixin): release() call resets the state to unlocked; first coroutine which is blocked in acquire() is being processed. - acquire() is a coroutine and should be called with 'yield from'. + acquire() is a coroutine and should be called with 'await'. - Locks also support the context management protocol. '(yield from lock)' - should be used as the context manager expression. + Locks also support the asynchronous context management protocol. + 'async with lock' statement should be used. Usage: lock = Lock() ... - yield from lock + await lock.acquire() try: ... finally: @@ -132,13 +139,13 @@ class Lock(_ContextManagerMixin): lock = Lock() ... - with (yield from lock): + async with lock: ... Lock objects can be tested for locking state: if not lock.locked(): - yield from lock + await lock.acquire() else: # lock is acquired ... |