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: No mechanism to abort created coroutine or suppress not-awaited warning
Type: enhancement Stage: resolved
Components: asyncio Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Sheng Zhong, asvetlov, ppperry, yselivanov
Priority: normal Keywords:

Created on 2018-08-22 22:02 by Sheng Zhong, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg323911 - (view) Author: Sheng Zhong (Sheng Zhong) Date: 2018-08-22 22:02
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?
msg323913 - (view) Author: (ppperry) Date: 2018-08-22 23:59
Does calling `coro.close()` not work?
msg344401 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-06-03 10:08
Could you consider passing (async_func, args, kwargs) tuple instead async_func(*args, **kwargs) coroutine?

Looks like it solves your problem and doesn't require asyncio changes
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78648
2019-06-11 10:09:28asvetlovsetstatus: open -> closed
resolution: wont fix
stage: resolved
2019-06-03 10:08:56asvetlovsetmessages: + msg344401
2018-08-22 23:59:51ppperrysetnosy: + ppperry
messages: + msg323913
2018-08-22 22:02:43Sheng Zhongcreate