Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Steve Dower
milar, but lighter weight than a regular future. Cheers, Steve Top-posted from my Windows Phone -Original Message- From: "Andrew Barnert via Python-Dev" Sent: ‎12/‎17/‎2015 6:37 To: "Paul Sokolovsky" Cc: "Python-Dev" Subject: Re: [Python-Dev] async/await

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Yury Selivanov
On 2015-12-16 1:11 AM, Nick Coghlan wrote: On 16 December 2015 at 11:41, Barry Warsaw wrote: The asyncio library documentation *really* needs a good overview and/or tutorial. These are difficult concepts to understand and it seems like bringing experience from other languages may not help (a

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Andrew Barnert via Python-Dev
> On Dec 16, 2015, at 03:25, Paul Sokolovsky wrote: > > Hello, > > On Tue, 15 Dec 2015 17:29:26 -0800 > Roy Williams wrote: > >> @Kevin correct, that's the point I'd like to discuss. Most other >> mainstream languages that implements async/await expose the >> programming model with Tasks/Futu

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/16/2015 01:11 AM, Nick Coghlan wrote: > One smaller step that may be helpful is changing the titles of a > couple of the sections from: > > * 18.5.4. Transports and protocols (low-level API) * 18.5.5. Streams > (high-level API) > > to: > > *

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Guido van Rossum
On Wed, Dec 16, 2015 at 1:50 AM, Roy Williams wrote: > I totally agree that async/await should not be tied to any underlying > message pump/event loop. Ensuring that async/await works with existing > systems like Tornado is great. > > As for the two options, option 1 is the expected behavior fro

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Yury Selivanov
On 2015-12-16 12:55 AM, Kevin Conway wrote: I think the list is trying to tell you that awaiting a coro multiple times is simply not a valid case in Python because they are exhaustible resources. In asyncio, they are primarily a helpful mechanism for shipping promises to the Task wrapper. In

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Paul Sokolovsky
Hello, On Tue, 15 Dec 2015 17:29:26 -0800 Roy Williams wrote: > @Kevin correct, that's the point I'd like to discuss. Most other > mainstream languages that implements async/await expose the > programming model with Tasks/Futures/Promises as opposed to > coroutines PEP 492 states 'Objects with

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-16 Thread Roy Williams
I totally agree that async/await should not be tied to any underlying message pump/event loop. Ensuring that async/await works with existing systems like Tornado is great. As for the two options, option 1 is the expected behavior from developers coming from other languages implementing async/awai

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Nick Coghlan
On 16 December 2015 at 11:41, Barry Warsaw wrote: > The asyncio library documentation *really* needs a good overview and/or > tutorial. These are difficult concepts to understand and it seems like > bringing experience from other languages may not help (and may even hinder) > understanding of Pyt

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Kevin Conway
I agree with Barry. We need more material that introduces the community to the new async/await syntax and the new concepts they bring. We borrowed the words from other languages but not all of their behaviours. With coroutines in particular, we can do a better job of describing the differences bet

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Yury Selivanov
Roy, On 2015-12-15 8:29 PM, Roy Williams wrote: [..] My proposal would be to automatically wrap the return value from an `async` function or any object implementing `__await__` in a future with `asyncio.ensure_future()`. This would allow async/await code to behave in a similar manner to oth

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Andrew Barnert via Python-Dev
On Dec 15, 2015, at 17:29, Roy Williams wrote: > > My proposal would be to automatically wrap the return value from an `async` > function or any object implementing `__await__` in a future with > `asyncio.ensure_future()`. This would allow async/await code to behave in a > similar manner to o

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Barry Warsaw
On Dec 15, 2015, at 05:29 PM, Roy Williams wrote: >@Kevin correct, that's the point I'd like to discuss. Most other >mainstream languages that implements async/await expose the programming >model with Tasks/Futures/Promises as opposed to coroutines PEP 492 states >'Objects with __await__ method

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Roy Williams
@Kevin correct, that's the point I'd like to discuss. Most other mainstream languages that implements async/await expose the programming model with Tasks/Futures/Promises as opposed to coroutines PEP 492 states 'Objects with __await__ method are called Future-like objects in the rest of this PEP.

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Guido van Rossum
On Tue, Dec 15, 2015 at 4:39 PM, Roy Williams wrote: > Thanks for the insight Guido. > > I've mostly used async/await inside of HHVM/Hack, and used Guava/Java > Futures extensively in the past so I found this behavior to be quite > surprising. I'd like to use Awaitables to represent a DAG of wor

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Roy Williams
Thanks for the insight Guido. I've mostly used async/await inside of HHVM/Hack, and used Guava/Java Futures extensively in the past so I found this behavior to be quite surprising. I'd like to use Awaitables to represent a DAG of work that needs to get done. For example, I used to be one of the

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Kevin Conway
I think there may be somewhat of a language barrier here. OP appears to be mixing the terms of coroutines and futures. The behavior OP describes is that of promised or async tasks in other languages. Consider a JS promise that has been resolved: promise.then(function (value) {...}); promise.then

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Guido van Rossum
Agreed. (But let's hear from the OP first.) On Tue, Dec 15, 2015 at 12:27 PM, Andrew Svetlov wrote: > Both Yury's suggestions sounds reasonable. > > On Tue, Dec 15, 2015 at 10:24 PM, Yury Selivanov > wrote: > > Hi Roy and Guido, > > > > On 2015-12-15 3:08 PM, Guido van Rossum wrote: > > [..] >

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Andrew Svetlov
Both Yury's suggestions sounds reasonable. On Tue, Dec 15, 2015 at 10:24 PM, Yury Selivanov wrote: > Hi Roy and Guido, > > On 2015-12-15 3:08 PM, Guido van Rossum wrote: > [..] >> >> >> I don't know how long you have been using async/await, but I wonder if >> it's possible that you just haven't g

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Yury Selivanov
Hi Roy and Guido, On 2015-12-15 3:08 PM, Guido van Rossum wrote: [..] I don't know how long you have been using async/await, but I wonder if it's possible that you just haven't gotten used to the typical usage patterns? In particular, your claim "anything that takes an `awaitable` has to kno

Re: [Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Guido van Rossum
I think this goes back all the way to a debate we had when we were discussing PEP 380 (which introduced 'yield from', on which 'await' is built). In fact I believe that the reason PEP 380 didn't make it into Python 2.7 was that this issue was unresolved at the time (the PEP author and I preferred t

[Python-Dev] async/await behavior on multiple calls

2015-12-15 Thread Roy Williams
Howdy, I'm experimenting with async/await in Python 3, and one very surprising behavior has been what happens when calling `await` twice on an Awaitable. In C#, Hack/HHVM, and the new async/await spec in Ecmascript 7. In Python, calling `await` multiple times results in all future results getting