Issue 32253: Deprecate old-style locking in asyncio/locks.py (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/76434

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:55 admin set github: 76434
2017-12-09 18:00:28 asvetlov set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-12-09 18:00:07 asvetlov set messages: +
2017-12-09 16:11:38 yselivanov set messages: +
2017-12-09 09:48:55 asvetlov set messages: +
2017-12-09 09:37:24 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2017-12-09 09:14:32 asvetlov set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest4667>
2017-12-08 09:00:55 asvetlov set components: + Library (Lib)
2017-12-08 08:59:40 asvetlov create