Issue 25888: awaiting on coroutine that is being awaited should be an error - Python tracker

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.

classification
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: yselivanov Nosy List: asvetlov, brett.cannon, gvanrossum, martin.panter, ncoghlan, python-dev, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2015-12-16 21:51 by yselivanov, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Issue25888.patch yselivanov, 2015-12-17 21:24 review
Messages (7)
msg256539 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-12-16 21:51
This problem was discussed in one of the asyncio issues here: https://github.com/python/asyncio/issues/288

I propose to raise a RuntimeError if an 'await' expression is used for a coroutine object that's being awaited on already.  This change shouldn't impact performance in any way.  It will prevent users from writing code that behaves in a very weird ways (see the github link for an example).
msg256565 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2015-12-16 23:42
Right.
msg256615 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-12-17 21:24
The patch is attached, please review.
msg258043 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2016-01-12 00:07
Will commit this patch tomorrow to 3.5 and 3.6.

It only affects coroutines (async defs): if an await expression is used on a coroutine object while it's being already awaited by another coroutine, a `RuntimeError("coroutine is being awaited already")` will be triggered.
msg258046 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-01-12 01:07
Missing word in a comment on the review
msg261125 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-03-02 16:31
New changeset e16084e07761 by Yury Selivanov in branch '3.5':
coroutines: Error when awaiting on coroutine that's being awaited
https://hg.python.org/cpython/rev/e16084e07761

New changeset 2218ce5c592f by Yury Selivanov in branch 'default':
Merge 3.5 (issue #25888)
https://hg.python.org/cpython/rev/2218ce5c592f
msg261126 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2016-03-02 16:33
Committed. Thanks for the review, Martin!