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.

Author tvoinarovskyi
Recipients asvetlov, tvoinarovskyi, yselivanov
Date 2020-10-23.16:10:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603469429.01.0.760360212477.issue42130@roundup.psfhosted.org>
In-reply-to
Content
Hi, during migration to Python 3.8.6 we encountered a behavior change from previous versions: wait_for ignored the request to cancellation and returned instead. After investigation, it seems to be related to the update in bpo-32751 and is only reproduced if the waited task is finished when cancellation of wait_for happens (code mistakes external CancelledError for a timeout).

The following example can reproduce the behavior on both 3.8.6 and 3.9.0 for me:

```

import asyncio


async def inner():
    return

async def with_for_coro():
    await asyncio.wait_for(inner(), timeout=100)
    await asyncio.sleep(1)
    print('End of with_for_coro. Should not be reached!')

async def main():
    task = asyncio.create_task(with_for_coro())
    await asyncio.sleep(0)
    assert not task.done()
    task.cancel()
    print('Called task.cancel()')
    await task  # -> You would expect a CancelledError to be raised.


asyncio.run(main())
```

Changing the wait time before cancellation slightly will return the correct behavior and CancelledError will be raised.
History
Date User Action Args
2020-10-23 16:10:29tvoinarovskyisetrecipients: + tvoinarovskyi, asvetlov, yselivanov
2020-10-23 16:10:29tvoinarovskyisetmessageid: <1603469429.01.0.760360212477.issue42130@roundup.psfhosted.org>
2020-10-23 16:10:28tvoinarovskyilinkissue42130 messages
2020-10-23 16:10:28tvoinarovskyicreate