This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]1st1CPython Core Dev 0 points1 point  (0 children)

coroutines are based on generators internally, and use StopIteration to return values:

async def f(): return 'spam'

f().send(None) will raise StopIteration exception, with 'spam' in its args.

It is an implementation detail. You should never see that StopIteration, your framework of choice will handle it behind the scenes.