[issue34467] No mechanism to abort created coroutine or suppress not-awaited warning

Sheng Zhong report at bugs.python.org
Wed Aug 22 18:02:43 EDT 2018


New submission from Sheng Zhong <zhsh at umich.edu>:

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?

----------
components: asyncio
messages: 323911
nosy: Sheng Zhong, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: No mechanism to abort created coroutine or suppress not-awaited warning
type: enhancement
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34467>
_______________________________________


More information about the Python-bugs-list mailing list