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
Title: awaiting on coroutine that is being awaited should be an error
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.6, Python 3.5
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!
History
Date User Action Args
2022-04-11 14:58:25adminsetgithub: 70076
2016-03-02 16:33:32yselivanovsetstatus: open -> closed
resolution: fixed
messages: + msg261126

stage: patch review -> resolved
2016-03-02 16:31:43python-devsetnosy: + python-dev
messages: + msg261125
2016-01-12 01:07:28martin.pantersetnosy: + martin.panter
messages: + msg258046
2016-01-12 00:07:49yselivanovsetmessages: + msg258043
2015-12-17 21:24:01yselivanovsetfiles: + Issue25888.patch
keywords: + patch
messages: + msg256615

stage: patch review
2015-12-17 17:33:31brett.cannonsetnosy: + brett.cannon
2015-12-16 23:42:35gvanrossumsetmessages: + msg256565
2015-12-16 21:51:12yselivanovcreate