Skip to content

condition lock not re-acquired #77819

Closed
Closed

Description

@christof
mannequin
BPO 33638
Nosy @asvetlov, @1st1, @miss-islington
PRs
  • bpo-32751: Wait for task cancellation in asyncio.wait_for() #7216
  • [3.7] bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216) #7223
  • Superseder
  • bpo-32751: wait_for(future, ...) should wait for the future (even if a timeout occurs)
  • 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 2018-05-30.01:01:18.215>
    created_at = <Date 2018-05-24.19:10:23.885>
    labels = ['type-bug', 'expert-asyncio']
    title = 'condition lock not re-acquired'
    updated_at = <Date 2018-05-30.01:01:18.214>
    user = 'https://bugs.python.org/christof'

    bugs.python.org fields:

    activity = <Date 2018-05-30.01:01:18.214>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-05-30.01:01:18.215>
    closer = 'yselivanov'
    components = ['asyncio']
    creation = <Date 2018-05-24.19:10:23.885>
    creator = 'christof'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33638
    keywords = ['patch']
    message_count = 5.0
    messages = ['317604', '317608', '318063', '318096', '318131']
    nosy_count = 4.0
    nosy_names = ['asvetlov', 'yselivanov', 'miss-islington', 'christof']
    pr_nums = ['7216', '7223']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = '32751'
    type = 'behavior'
    url = 'https://bugs.python.org/issue33638'
    versions = ['Python 3.6']

    Activity

    1. christof commented on May 24, 2018

      christofmannequin
      MannequinAuthor

      Hello,

      I have a simple code which triggers a timeout if a task did not complete

      import asyncio
      
      async def task_timeout():
          condition = asyncio.Condition()
          with await condition:
              try:
                  await asyncio.wait_for(condition.wait(), timeout=4)
              except asyncio.TimeoutError as e:
       
                  print("timeout reached")
                  # uncomment this line to make the code work
                  # await asyncio.sleep(0)
      
      
      f = asyncio.ensure_future(task_timeout())
      
      loop= asyncio.get_event_loop()
      loop.run_until_complete(f)

      It throws an exception when leaving the scope for the condition because it expects the lock to be acquired:

      RuntimeError: Lock is not acquired.

      If you uncomment the line to sleep, it will work because it will continue in the coroutine Condition.wait and call:
      yield from self.acquire() => locks.py line 355

      I think this is a bug and that this behaviour is not the expected one.

    2. added
      type-bug
      on May 24, 2018
    3. christof commented on May 24, 2018

      christofmannequin
      MannequinAuthor

      In my previous comment, what I want to implement is not a timeout for a task to complete but more precisely a timeout triggered if the coroutine was not wake up by a notify on the condition.

    4. 1st1 commented on May 29, 2018

      @1st1
      Member

      This is caused by wait_for not waiting for the cancelled task. https://bugs.python.org/issue32751 tracks that bug.

    5. 1st1 commented on May 29, 2018

      @1st1
      Member

      New changeset e2b340a by Yury Selivanov (Elvis Pranskevichus) in branch 'master':
      bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
      e2b340a

    6. miss-islington commented on May 29, 2018

      @miss-islington
      Contributor

      New changeset d8948c5 by Miss Islington (bot) in branch '3.7':
      bpo-32751: Wait for task cancellation in asyncio.wait_for() (GH-7216)
      d8948c5

    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

      topic-asynciotype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions