[Python-ideas] Re: asyncio: futures and tasks with synchronous callbacks

2019-08-01 Thread Andrew Svetlov
Agree with Aurelien Lambert: if you call task.cancel() there is no sense for expecting a normal result from a task. My typical code for task cancellation looks like task.cancel() with contextlib.suppress(asyncio.CancelledError): await task If you need a partial task result you probably can bu

[Python-ideas] Re: asyncio: futures and tasks with synchronous callbacks

2019-07-31 Thread aurelien . lambert . 89
Which means you cancel a running task but still have to wait for it and check if it eventually has a result. This is OK for internal use, but highly counter intuitive for the end-user. And it makes the cancelled status even more inconsistent, as calling cancel on a running task does not ensure i

[Python-ideas] Re: asyncio: futures and tasks with synchronous callbacks

2019-07-31 Thread Bar Harel
Aren't you able to catch the cancellation error and retrieve the data from the inner task's .result()? On Wed, Jul 31, 2019, 8:00 AM Guido van Rossum wrote: > I wonder if Nathaniel has something to add? Trio has a different approayto > cancellation. Of course it is also an entirely new library..

[Python-ideas] Re: asyncio: futures and tasks with synchronous callbacks

2019-07-30 Thread Guido van Rossum
I wonder if Nathaniel has something to add? Trio has a different approayto cancellation. Of course it is also an entirely new library... On Tue, Jul 30, 2019 at 9:51 PM wrote: > Oh only now it appears in the list ! I thought the post hadn't working, so > I posted again :/. > > I've fixed my "lib

[Python-ideas] Re: asyncio: futures and tasks with synchronous callbacks

2019-07-30 Thread aurelien . lambert . 89
Oh only now it appears in the list ! I thought the post hadn't working, so I posted again :/. I've fixed my "library" (https://github.com/aure-olli/aiokafka/blob/3acb88d6ece4502a78e230b234f47b90b9d30fd5/syncio.py), and the `wrapped_consumer2` function. Now no double await, so no risk of afterw

[Python-ideas] Re: asyncio: futures and tasks with synchronous callbacks

2019-07-30 Thread Guido van Rossum
It seems inevitable that if you use await twice you risk being cancelled in between. The solution is to only use a single await to do all the work, like asyncio.queue does (and why not use that for your use case?). I don't think inventing a parallel API of synchronous callbacks is a good idea -- as