Re: [Python-Dev] Importance of "async" keyword

2015-07-07 Thread Nick Coghlan
On 7 July 2015 at 06:08, Sven R. Kunze wrote: > I would like to rewrite/amend it to work asynchronously with minimal effort > such as: > > def business_new(): > content1 = fork open('big.file').read() # wraps up the calls into > awaitables > content2 = fork open('huge.file').read() # and

Re: [Python-Dev] Importance of "async" keyword

2015-07-06 Thread Sven R. Kunze
On 06.07.2015 03:41, Nick Coghlan wrote: That said, I think there's definitely value in providing a very simple answer to the "how do I make a blocking call from a coroutine?" question, so I filed an RFE to add asyncio.blocking_call: http://bugs.python.org/issue24571 Nice step forward, Nick. Th

Re: [Python-Dev] Importance of "async" keyword

2015-07-05 Thread Nick Coghlan
On 6 July 2015 at 10:49, Steven D'Aprano wrote: > On Sun, Jul 05, 2015 at 11:50:00PM +0200, Sven R. Kunze wrote: > >> Seems like we stick to this example once again. So, let me get this >> straight: >> >> 1) I can add, subtract, multiply and divide real numbers. >> 2) I can add, subtract, multiply

Re: [Python-Dev] Importance of "async" keyword

2015-07-05 Thread Steve Dower
other language that implemented this exact model a few years ago and it works well. Cheers, Steve Top-posted from my Windows Phone From: Sven R. Kunze<mailto:srku...@mail.de> Sent: ‎7/‎5/‎2015 14:50 To: python-dev@python.org<mailto:python-dev@python.o

Re: [Python-Dev] Importance of "async" keyword

2015-07-05 Thread Nick Coghlan
On 6 July 2015 at 10:27, Chris Angelico wrote: > On Mon, Jul 6, 2015 at 7:50 AM, Sven R. Kunze wrote: >> Seems like we stick to this example once again. So, let me get this >> straight: >> >> 1) I can add, subtract, multiply and divide real numbers. >> 2) I can add, subtract, multiply and divide

Re: [Python-Dev] Importance of "async" keyword

2015-07-05 Thread Steven D'Aprano
On Sun, Jul 05, 2015 at 11:50:00PM +0200, Sven R. Kunze wrote: > Seems like we stick to this example once again. So, let me get this > straight: > > 1) I can add, subtract, multiply and divide real numbers. > 2) I can add, subtract, multiply and divide complex numbers. I don't think that this i

Re: [Python-Dev] Importance of "async" keyword

2015-07-05 Thread Chris Angelico
On Mon, Jul 6, 2015 at 7:50 AM, Sven R. Kunze wrote: > Seems like we stick to this example once again. So, let me get this > straight: > > 1) I can add, subtract, multiply and divide real numbers. > 2) I can add, subtract, multiply and divide complex numbers. > 3) I can even add, subtract, multipl

Re: [Python-Dev] Importance of "async" keyword

2015-07-05 Thread Sven R. Kunze
Thanks, Nick, for you reasoned response. On 03.07.2015 11:40, Nick Coghlan wrote: On 3 July 2015 at 06:55, Sven R. Kunze wrote: My understanding of coloring is "needs special treatment". Being special or not (containing an 'await' or not), as long as I don't need to care, I can call them eith

Re: [Python-Dev] Importance of "async" keyword

2015-07-03 Thread Nick Coghlan
On 3 July 2015 at 06:55, Sven R. Kunze wrote: > My understanding of coloring is "needs special treatment". > > Being special or not (containing an 'await' or not), as long as I don't need > to care, I can call them either way (with 'await' or not) and each case > works sensibly that's fine with me

Re: [Python-Dev] Importance of "async" keyword

2015-07-02 Thread Sven R. Kunze
My understanding of coloring is "needs special treatment". Being special or not (containing an 'await' or not), as long as I don't need to care, I can call them either way (with 'await' or not) and each case works sensibly that's fine with me. Sensible would be something similar to: call fun

Re: [Python-Dev] Importance of "async" keyword

2015-07-01 Thread Greg Ewing
Sven R. Kunze wrote: I like the 'await' syntax to mark suspension points. But the 'async' coloring makes no sense to me. It is an implementation details of asyncio (IMHO). Functions containing an "await" are going to be coloured in any case -- that's unavoidable, given that await is built on t

Re: [Python-Dev] Importance of "async" keyword

2015-06-30 Thread Sven R. Kunze
Hi, I have never said I wanted implicit asyncio. Explicit is the Python way after all, it served me well and I stick to that. I like the 'await' syntax to mark suspension points. But the 'async' coloring makes no sense to me. It is an implementation details of asyncio (IMHO). From what I

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Jim J. Jewett
On Fri Jun 26 16:51:13 CEST 2015, Paul Sokolovsky wrote: > So, currently in Python you know if you do: >socket.write(buf) > Then you know it will finish without interruptions for entire buffer. How do you know that? Are you assuming that socket.write is a builtin, rather than a python me

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Nick Coghlan
On 27 June 2015 at 04:06, Ron Adam wrote: > It seems that those points are defined by other means outside of a function > defined with "async def". From the PEP... > >* It is a SyntaxError to have yield or yield from expressions > in an async function. > > So somewhere in an async functi

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Steve Dower
Ethan Furman wrote: > On 06/26/2015 08:47 AM, Steve Dower wrote: >> On 06/26/2015 06:48 AM, Sven R. Kunze wrote: >> >>> def business(): >>> return complex_calc(5) >>> >>> def business_new() >>> return await complex_calc(10) > >> Assuming "async def business_new" (to avoid the syntax error), there'

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Yury Selivanov
On 2015-06-26 1:40 PM, Ethan Furman wrote: On 06/26/2015 08:47 AM, Steve Dower wrote: On 06/26/2015 06:48 AM, Sven R. Kunze wrote: def business(): return complex_calc(5) def business_new() return await complex_calc(10) Assuming "async def business_new" (to avoid the syntax err

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Ron Adam
On 06/26/2015 10:31 AM, Chris Angelico wrote: Apologies if this is a really REALLY dumb question, but... How hard would it be to then dispense with the await keyword, and simply _always_ behave that way? Something like: def data_from_socket(): # Other tasks may run while we wait for data

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Ethan Furman
On 06/26/2015 08:47 AM, Steve Dower wrote: On 06/26/2015 06:48 AM, Sven R. Kunze wrote: def business(): return complex_calc(5) def business_new() return await complex_calc(10) Assuming "async def business_new" (to avoid the syntax error), there's no difference between those fun

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Nick Coghlan
On 27 June 2015 at 00:31, Chris Angelico wrote: > I come from a background of thinking with threads, so I'm accustomed > to doing blocking I/O and assuming/expecting that other threads will > carry on while we wait. If asynchronous I/O can be made that > convenient, it'd be awesome. Folks, it's w

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Steve Dower
On 06/26/2015 06:48 AM, Sven R. Kunze wrote: > def business(): > return complex_calc(5) > > def business_new() > return await complex_calc(10) > Maybe, I completely missed the point of the proposal, but this is the way I > would expect it to work. Putting in an 'await' whenever I see f

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Nick Coghlan
On 26 June 2015 at 23:48, Sven R. Kunze wrote: > @Nick > Thanks for these links; nice reads and reflect exactly what I think about > these topics. Btw. complex numbers basically works the same way (same API) > as integers. Not using complex numbers in Python - coming to grips with what they mean

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Chris Angelico
On Sat, Jun 27, 2015 at 2:07 AM, R. David Murray wrote: > On Sat, 27 Jun 2015 01:10:33 +1000, Chris Angelico wrote: >> The way I'm seeing it, coroutines are like cooperatively-switched >> threads; you don't have to worry about certain operations being >> interrupted (particularly low-level ones l

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread R. David Murray
On Sat, 27 Jun 2015 01:10:33 +1000, Chris Angelico wrote: > The way I'm seeing it, coroutines are like cooperatively-switched > threads; you don't have to worry about certain operations being > interrupted (particularly low-level ones like refcount changes or list > growth), but any time you hit a

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Yury Selivanov
On 2015-06-26 10:31 AM, Chris Angelico wrote: On Sat, Jun 27, 2015 at 12:20 AM, Ethan Furman wrote: >As Nick said earlier: the caller always blocks; by extension (to my mind, at >least) putting an `await` in front of something is saying, "it's okay if >other tasks run while I'm blocking on th

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Chris Angelico
On Sat, Jun 27, 2015 at 12:51 AM, Paul Sokolovsky wrote: > Some say "convenient", others say "dangerous". > > Consider: > > buf = bytearray(MULTIMEGABYTE) > > In one function you do: > > socket.write(buf), > > in another function (coroutine), you keep mutating buf. > > So, currently in Python you

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Paul Sokolovsky
Hello, On Sat, 27 Jun 2015 00:31:01 +1000 Chris Angelico wrote: > On Sat, Jun 27, 2015 at 12:20 AM, Ethan Furman > wrote: > > As Nick said earlier: the caller always blocks; by extension (to my > > mind, at least) putting an `await` in front of something is saying, > > "it's okay if other tasks

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Chris Angelico
On Sat, Jun 27, 2015 at 12:20 AM, Ethan Furman wrote: > As Nick said earlier: the caller always blocks; by extension (to my mind, at > least) putting an `await` in front of something is saying, "it's okay if > other tasks run while I'm blocking on this call." Apologies if this is a really REALLY

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Ethan Furman
On 06/26/2015 06:48 AM, Sven R. Kunze wrote: def business(): return complex_calc(5) def business_new() return await complex_calc(10) Maybe, I completely missed the point of the proposal, but this is the way I would expect it to work. Putting in an 'await' whenever I see fit and it

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Sven R. Kunze
On 25.06.2015 21:11, Andrew Svetlov wrote: Another issue that bothers me, is code reuse. Independent from whether the 'async def' makes sense or not, it would not allow us to reuse asyncio functions as if they were normal functions and vice versa (if I understood that correctly). So, we would hav

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Nick Coghlan
On 26 Jun 2015 10:46, "Greg Ewing" wrote: > > Sven R. Kunze wrote: >> So, we would have to implement things twice for the asyncio world and the classic world. > > > Not exactly; it's possible to create a wrapper that takes an > async function and runs it to completion, allowing it to be > called f

Re: [Python-Dev] Importance of "async" keyword

2015-06-26 Thread Nick Coghlan
On 26 Jun 2015 05:15, "Andrew Svetlov" wrote: > > > Another issue that bothers me, is code reuse. Independent from whether the > > 'async def' makes sense or not, it would not allow us to reuse asyncio > > functions as if they were normal functions and vice versa (if I understood > > that correctl

Re: [Python-Dev] Importance of "async" keyword

2015-06-25 Thread Steven D'Aprano
On Thu, Jun 25, 2015 at 05:55:53PM +0200, Sven R. Kunze wrote: > > On 25.06.2015 04:16, Steven D'Aprano wrote: > >On Wed, Jun 24, 2015 at 11:21:54PM +0200, Sven R. Kunze wrote: [...] > >>What is the difference of a function (no awaits) or an awaitable (> 1 > >>awaits) from an end-user's perspectiv

Re: [Python-Dev] Importance of "async" keyword

2015-06-25 Thread Greg Ewing
Sven R. Kunze wrote: # Call func syncronously, blocking until the calculation is done: x = func() # Call func asyncronously, without blocking: y = await func() Using the word "blocking" this way is potentially confusing. The calling task is *always* blocked until the operation completes. The

Re: [Python-Dev] Importance of "async" keyword

2015-06-25 Thread Andrew Svetlov
> Another issue that bothers me, is code reuse. Independent from whether the > 'async def' makes sense or not, it would not allow us to reuse asyncio > functions as if they were normal functions and vice versa (if I understood > that correctly). So, we would have to implement things twice for the a

Re: [Python-Dev] Importance of "async" keyword

2015-06-25 Thread Sven R. Kunze
On 25.06.2015 04:16, Steven D'Aprano wrote: On Wed, Jun 24, 2015 at 11:21:54PM +0200, Sven R. Kunze wrote: Thanks, Yury, for you quick response. On 24.06.2015 22:16, Yury Selivanov wrote: Sven, if we don't have 'async def', and instead say that "a function is a *coroutine function* when it ha

Re: [Python-Dev] Importance of "async" keyword

2015-06-24 Thread Steven D'Aprano
On Wed, Jun 24, 2015 at 11:21:54PM +0200, Sven R. Kunze wrote: > Thanks, Yury, for you quick response. > > On 24.06.2015 22:16, Yury Selivanov wrote: > >Sven, if we don't have 'async def', and instead say that "a function > >is a *coroutine function* when it has at least one 'await' > >expressio

Re: [Python-Dev] Importance of "async" keyword

2015-06-24 Thread Sven R. Kunze
Thanks, Yury, for you quick response. On 24.06.2015 22:16, Yury Selivanov wrote: Sven, if we don't have 'async def', and instead say that "a function is a *coroutine function* when it has at least one 'await' expression", then when you refactor "useful()" by removing the "await" from it, it st

Re: [Python-Dev] Importance of "async" keyword

2015-06-24 Thread Yury Selivanov
Hi Sven, On 2015-06-24 2:14 PM, Sven R. Kunze wrote: Hi everybody, recently, I stumbled over the new 3.5 release and in doing so over PEP 0492. After careful consideration and after reading many blog posts of various coders, I first would like to thank Yury Selivanov and everybody else who

[Python-Dev] Importance of "async" keyword

2015-06-24 Thread Sven R. Kunze
Hi everybody, recently, I stumbled over the new 3.5 release and in doing so over PEP 0492. After careful consideration and after reading many blog posts of various coders, I first would like to thank Yury Selivanov and everybody else who brought PEP 0492 to its final state. I therefore conside