New submission from Sheng Zhong <z...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue34467>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to