Skip to content

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

Closed

Description

@asvetlov
BPO 32253
Nosy @asvetlov, @serhiy-storchaka, @1st1
PRs
  • bpo-32253: Deprecate with statement and bare await for asyncio locks #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']

    Activity

    1. asvetlov commented on Dec 8, 2017

      @asvetlov
      ContributorAuthor

      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:
          ...
    2. added
      3.7 (EOL)
      stdlib
      on Dec 8, 2017
    3. serhiy-storchaka commented on Dec 9, 2017

      @serhiy-storchaka
      Member

      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?

    4. asvetlov commented on Dec 9, 2017

      @asvetlov
      ContributorAuthor
      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 bpo-32193: Convert asyncio to async/await usage #4753 (comment)
    5. 1st1 commented on Dec 9, 2017

      @1st1
      Member

      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.

    6. asvetlov commented on Dec 9, 2017

      @asvetlov
      ContributorAuthor

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

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)stdlibtopic-asyncio

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions