This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Deprecate old-style locking in asyncio/locks.py
Type: Stage: resolved
Components: asyncio, Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, serhiy.storchaka, yselivanov
Priority: normal Keywords: patch

Created on 2017-12-08 08:59 by asvetlov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 4764 merged asvetlov, 2017-12-09 09:14
Messages (5)
msg307839 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2017-12-08 08:59
Now constructions like

await lock  # "yield from lock" can be used as well
try:
    ...
finally:
    lock.release()

and

with (yield from lock):
    ...

are supported. Let's deprecate them in favor of

async with lock:
    ...
msg307887 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-12-09 09:37
This can make harder writing portable code that works in 2.7, 3.4 and 3.7.

What is the benefit of the deprecation? Are there inevitable design or implementation errors in these constructions? Or getting rid of them can significantly simplify the implementation?
msg307888 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2017-12-09 09:48
1. asyncio is not supported by 2.7 anyway
2. with (yield from lock) is based on very non-obvious tricks:
  a) lock.__enter__ is forbidden and raises RuntimeError
  b) actually lock.__iter__ is called for lock acquiring *before* calling `with`
  c) the object returned from __iter__ is a context manager with __enter__/__exit__ methods
3. asyncio is converted to async/await syntax by https://bugs.python.org/issue32193 (old `yield from` style is fully supported still).
4. the deprecation was proposed by Yury Selivanov in https://github.com/python/cpython/pull/4753#discussion_r155658200
msg307903 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2017-12-09 16:11
> This can make harder writing portable code that works in 2.7, 3.4 and 3.7.

asyncio for Python 3.4 is fairly outdated.  Most of the async packages today require 3.5+, as they usually use async/await syntax.  I say this sort of backwards compatibility (showing a warning) isn't really a big concern.  A bigger concern for us is new code using 'with await lock' pattern, hence the warning.
msg307905 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2017-12-09 18:00
New changeset 28d8d14013ade0657fed4673f5fa3c08eb2b1944 by Andrew Svetlov in branch 'master':
bpo-32253: Deprecate with statement and bare await for asyncio locks (GH-4764)
https://github.com/python/cpython/commit/28d8d14013ade0657fed4673f5fa3c08eb2b1944
History
Date User Action Args
2022-04-11 14:58:55adminsetgithub: 76434
2017-12-09 18:00:28asvetlovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-12-09 18:00:07asvetlovsetmessages: + msg307905
2017-12-09 16:11:38yselivanovsetmessages: + msg307903
2017-12-09 09:48:55asvetlovsetmessages: + msg307888
2017-12-09 09:37:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg307887
2017-12-09 09:14:32asvetlovsetkeywords: + patch
stage: patch review
pull_requests: + pull_request4667
2017-12-08 09:00:55asvetlovsetcomponents: + Library (Lib)
2017-12-08 08:59:40asvetlovcreate