Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate old-style locking in asyncio/locks.py #76434

Closed
asvetlov opened this issue Dec 8, 2017 · 5 comments
Closed

Deprecate old-style locking in asyncio/locks.py #76434

asvetlov opened this issue Dec 8, 2017 · 5 comments
Labels
3.7 expert-asyncio stdlib

Comments

@asvetlov
Copy link
Contributor

@asvetlov asvetlov commented Dec 8, 2017

BPO 32253
Nosy @asvetlov, @serhiy-storchaka, @1st1
PRs
  • #4764
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-12-09.18:00:28.630>
    created_at = <Date 2017-12-08.08:59:40.579>
    labels = ['3.7', 'library', 'expert-asyncio']
    title = 'Deprecate old-style locking in asyncio/locks.py'
    updated_at = <Date 2017-12-09.18:00:28.629>
    user = 'https://github.com/asvetlov'

    bugs.python.org fields:

    activity = <Date 2017-12-09.18:00:28.629>
    actor = 'asvetlov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-12-09.18:00:28.630>
    closer = 'asvetlov'
    components = ['Library (Lib)', 'asyncio']
    creation = <Date 2017-12-08.08:59:40.579>
    creator = 'asvetlov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32253
    keywords = ['patch']
    message_count = 5.0
    messages = ['307839', '307887', '307888', '307903', '307905']
    nosy_count = 3.0
    nosy_names = ['asvetlov', 'serhiy.storchaka', 'yselivanov']
    pr_nums = ['4764']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue32253'
    versions = ['Python 3.7']

    @asvetlov
    Copy link
    Contributor Author

    @asvetlov asvetlov commented Dec 8, 2017

    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:
        ...

    @asvetlov asvetlov added 3.7 expert-asyncio stdlib labels Dec 8, 2017
    @serhiy-storchaka
    Copy link
    Member

    @serhiy-storchaka serhiy-storchaka commented Dec 9, 2017

    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?

    @asvetlov
    Copy link
    Contributor Author

    @asvetlov asvetlov commented Dec 9, 2017

    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 #4753 (comment)

    @1st1
    Copy link
    Member

    @1st1 1st1 commented Dec 9, 2017

    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.

    @asvetlov
    Copy link
    Contributor Author

    @asvetlov asvetlov commented Dec 9, 2017

    New changeset 28d8d14 by Andrew Svetlov in branch 'master':
    bpo-32253: Deprecate with statement and bare await for asyncio locks (GH-4764)
    28d8d14

    @asvetlov asvetlov closed this as completed Dec 9, 2017
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 expert-asyncio stdlib
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants