classification
Title: AsyncGenerator breaks when not iterated fully with RuntimeError("can't send non-None value to a just-started coroutine")
Type: behavior Stage: resolved
Components: asyncio Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: asvetlov Nosy List: Michael Yoo, asvetlov, lukasz.langa, miss-islington, ned.deily, xtreak, yselivanov
Priority: release blocker Keywords: 3.7regression, patch

Created on 2019-09-03 00:13 by Michael Yoo, last changed 2019-09-17 13:20 by asvetlov. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 16061 closed asvetlov, 2019-09-12 14:52
PR 16070 merged asvetlov, 2019-09-12 16:34
PR 16231 merged miss-islington, 2019-09-17 13:00
PR 16232 merged miss-islington, 2019-09-17 13:00
Messages (7)
msg351044 - (view) Author: Michael Yoo (Michael Yoo) Date: 2019-09-03 00:13
Version: Python 3.7.3

When I run this code:

import asyncio


class TestAsyncGenerator:
    def __init__(self):
        pass

    async def aiter(self):
        yield 1
        yield 2


async def main():
    gen = TestAsyncGenerator()
    async for number in gen.aiter():
        break


asyncio.run(main())

# unhandled exception during asyncio.run() shutdown
# task: <Task finished coro=<<async_generator_athrow without __name__>()> exception=RuntimeError("can't send non-None value to a just-started coroutine")>
# RuntimeError: can't send non-None value to a just-started coroutine


There is a warning message that I don't expect to see. I would expect breaking from an async iteration to behave as if breaking from a normal iteration - that is, no problems.

However, I see the warning message shown above. Am I missing something? Otherwise, I believe this is a bug. Thanks!
msg352486 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-09-15 17:18
I have a PR for the fix.
Yuri preliminary agrees with the patch but he requested more time for careful review.

I've added 'release blocker' priority to don't miss this bugfix for the next release.
msg352598 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2019-09-17 05:15
> I've added 'release blocker' priority to don't miss this bugfix for the next release.

Note that 3.7.5rc1 is scheduled to be tagged today so we need to make a decision on whether to hold the release for a fix.  From a quick test, it looks like the behavior was introduced in 3.7.1 as the test does not fail for me with 3.7.0. If so, that seems to meet the criteria for a maintenance release regression and thus potentially a release blocker.
msg352603 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-09-17 06:18
Thanks, Ned.
I love to include this in 3.7.5.
I've pinged Yuri offline with ask for review
msg352634 - (view) Author: miss-islington (miss-islington) Date: 2019-09-17 12:59
New changeset c275312a6284bd319ea33c9abd7e15c230eca43f by Miss Islington (bot) (Andrew Svetlov) in branch 'master':
bpo-38013: make async_generator_athrow object tolerant to throwing exceptions (GH-16070)
https://github.com/python/cpython/commit/c275312a6284bd319ea33c9abd7e15c230eca43f
msg352636 - (view) Author: miss-islington (miss-islington) Date: 2019-09-17 13:19
New changeset fc022f04b41a79cacdff380435c30c8042c82b99 by Miss Islington (bot) in branch '3.7':
bpo-38013: make async_generator_athrow object tolerant to throwing exceptions (GH-16070)
https://github.com/python/cpython/commit/fc022f04b41a79cacdff380435c30c8042c82b99
msg352637 - (view) Author: miss-islington (miss-islington) Date: 2019-09-17 13:20
New changeset 3c1786f18b1542e71454f37e3f3ca1ef3eec0e5f by Miss Islington (bot) in branch '3.8':
bpo-38013: make async_generator_athrow object tolerant to throwing exceptions (GH-16070)
https://github.com/python/cpython/commit/3c1786f18b1542e71454f37e3f3ca1ef3eec0e5f
History
Date User Action Args
2019-09-17 13:20:51asvetlovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-09-17 13:20:10miss-islingtonsetmessages: + msg352637
2019-09-17 13:19:32miss-islingtonsetmessages: + msg352636
2019-09-17 13:00:12miss-islingtonsetpull_requests: + pull_request15829
2019-09-17 13:00:01miss-islingtonsetpull_requests: + pull_request15828
2019-09-17 12:59:54miss-islingtonsetnosy: + miss-islington
messages: + msg352634
2019-09-17 06:18:41asvetlovsetmessages: + msg352603
2019-09-17 05:15:34ned.deilysetkeywords: + 3.7regression
assignee: asvetlov
messages: + msg352598
2019-09-15 17:18:18asvetlovsetpriority: normal -> release blocker
versions: + Python 3.8, Python 3.9
nosy: + ned.deily, lukasz.langa

messages: + msg352486
2019-09-12 21:35:01xtreaklinkissue37455 superseder
2019-09-12 16:41:13xtreaksetnosy: + xtreak
2019-09-12 16:34:14asvetlovsetpull_requests: + pull_request15691
2019-09-12 14:52:47asvetlovsetkeywords: + patch
stage: patch review
pull_requests: + pull_request15684
2019-09-03 00:13:42Michael Yoocreate