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 chris.jerdonek
Recipients Martin.Teichmann, chris.jerdonek, gvanrossum, yselivanov
Date 2017-08-07.12:25:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1502108742.51.0.524180523982.issue29432@psf.upfronthosting.co.za>
In-reply-to
Content
I noticed that the future defined by asyncio.gather(sleep) is in a "pending" state immediately after the asyncio.TimeoutError.

One workaround is to wait for the cancellation to finish:

    @asyncio.coroutine
    def main():
        sleep = asyncio.sleep(0.2)
        future = asyncio.gather(sleep)
        try:
            yield from asyncio.wait_for(future, timeout=0.1)
        except asyncio.TimeoutError:
            print(f'future: {future}')
            try:
                yield from future
            except asyncio.CancelledError:
                print(f'future: {future}')
        yield from asyncio.sleep(0.1)

    asyncio.get_event_loop().run_until_complete(main())

Outputs:

    future: <_GatheringFuture pending>
    future: <_GatheringFuture finished exception=CancelledError()>

Another option is to pass return_exceptions=True to gather(). This appears to make the log messages you were concerned about go away:

    future: <_GatheringFuture pending>
History
Date User Action Args
2017-08-07 12:25:42chris.jerdoneksetrecipients: + chris.jerdonek, gvanrossum, yselivanov, Martin.Teichmann
2017-08-07 12:25:42chris.jerdoneksetmessageid: <1502108742.51.0.524180523982.issue29432@psf.upfronthosting.co.za>
2017-08-07 12:25:42chris.jerdoneklinkissue29432 messages
2017-08-07 12:25:42chris.jerdonekcreate