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 pyneda
Recipients asvetlov, giampaolo.rodola, pyneda, yselivanov
Date 2018-05-16.03:42:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1526442166.13.0.682650639539.issue33403@psf.upfronthosting.co.za>
In-reply-to
Content
A possible use case (that at least I couldn't find how to solve) is the possibility to cancel a bunch of futures/coroutine objects which are being awaited using asyncio.tasks.wait() by one of the running coroutines when a task succeded or a specific condition happens by just raising an specific exception.

At the moment this can be done but it will cancel all the coroutines with any exception that is raised and at some occasions this may not be desired.

A simple example:

async def example(num):
    if x == 5:
        raise Exception('Exception that does not cancel')
    elif x == 15:
        raise CancelException()

tasks = [asyncio.ensure_future(example(x)) for x in range(20)]
done, pending = await asyncio.wait(tasks, return_when=FIRST_EXCEPTION, return_on=CancelException)

This wouldn't cancel everything when a normal exception is raised, instead it will when the exception raised is the one that the user expects to be raised in order to cancel everything that is pending. 

In addition, if the user does not specify the Exception type, it uses default Exception so it would keep working exactly as now.
History
Date User Action Args
2018-05-16 03:42:46pynedasetrecipients: + pyneda, giampaolo.rodola, asvetlov, yselivanov
2018-05-16 03:42:46pynedasetmessageid: <1526442166.13.0.682650639539.issue33403@psf.upfronthosting.co.za>
2018-05-16 03:42:46pynedalinkissue33403 messages
2018-05-16 03:42:45pynedacreate