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 Sheng Zhong
Recipients Sheng Zhong, asvetlov, yselivanov
Date 2018-08-22.22:02:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1534975363.12.0.56676864532.issue34467@psf.upfronthosting.co.za>
In-reply-to
Content
As far as I know, there is no mechanism for aborting a created coroutine instance before it's executed with an await (directly or indirectly). I have a function which takes in coroutine instances and conditionally creates a task for them that I track so that they can be later gathered. When the condition is false, I'd like to not execute the passed in coroutine.

Simply ignoring the coroutine works but reports a RuntimeWarning about coroutine not being awaited on. Checking the conditional before calling the function works but damages maintainability and is putting the responsibility on the wrong party.

Creating the task then immediately cancelling it does not work since execution for it will start and leads to other cancellation issues.

Is there a way to abort a coroutine instance that I'm not aware of?
History
Date User Action Args
2018-08-22 22:02:43Sheng Zhongsetrecipients: + Sheng Zhong, asvetlov, yselivanov
2018-08-22 22:02:43Sheng Zhongsetmessageid: <1534975363.12.0.56676864532.issue34467@psf.upfronthosting.co.za>
2018-08-22 22:02:43Sheng Zhonglinkissue34467 messages
2018-08-22 22:02:42Sheng Zhongcreate