Re: Question about asyncio doc example

2014-07-24 Thread Marko Rauhamaa
Ian Kelly : > Callbacks can easily schedule coroutines, but they can't wait on them, > because that would require suspending their execution, dropping back > to the event loop, and resuming later -- in other words, the callback > would need to be a coroutine also. I guess the key is, can a callba

Re: Question about asyncio doc example

2014-07-24 Thread Ian Kelly
On Jul 24, 2014 1:26 AM, "Marko Rauhamaa" wrote: > > Terry Reedy : > > > 18.5.3. Tasks and coroutines, seems to be devoid of event wait > > examples. However, there is a 'yield from' network example in 18.5.5 > > Streams using socket functions wrapped with coroutines. These should > > definitely b

Re: Question about asyncio doc example

2014-07-24 Thread Marko Rauhamaa
Terry Reedy : > 18.5.3. Tasks and coroutines, seems to be devoid of event wait > examples. However, there is a 'yield from' network example in 18.5.5 > Streams using socket functions wrapped with coroutines. These should > definitely be used instead of sleep. In fact, for cross-platform > network

Re: Question about asyncio doc example

2014-07-24 Thread Terry Reedy
On 7/24/2014 1:15 AM, Saimadhav Heblikar wrote: On 24 July 2014 05:54, Terry Reedy wrote: On 7/23/2014 6:43 AM, Saimadhav Heblikar wrote: Hi, The example in question is https://docs.python.org/3/library/asyncio-task.html#example-hello-world-coroutine. I'd like to learn the purpose of the st

Re: Question about asyncio doc example

2014-07-23 Thread Marko Rauhamaa
Saimadhav Heblikar : > For situations where I dont really know how long a function is going > to take(say waiting for user input or a network operation), I am > better off using callbacks than "yield from asyncio.sleep()". Is my > understanding correct? If you choose the coroutine style of progra

Re: Question about asyncio doc example

2014-07-23 Thread Saimadhav Heblikar
On 24 July 2014 05:54, Terry Reedy wrote: > On 7/23/2014 6:43 AM, Saimadhav Heblikar wrote: >> >> Hi, >> >> The example in question is >> >> https://docs.python.org/3/library/asyncio-task.html#example-hello-world-coroutine. >> I'd like to learn the purpose of the statement >> "yield from asyncio.s

Re: Question about asyncio doc example

2014-07-23 Thread Terry Reedy
On 7/23/2014 6:43 AM, Saimadhav Heblikar wrote: Hi, The example in question is https://docs.python.org/3/library/asyncio-task.html#example-hello-world-coroutine. I'd like to learn the purpose of the statement "yield from asyncio.sleep(2)" in that example. In particular, I'd like to know if asyn

Re: Question about asyncio doc example

2014-07-23 Thread Yaşar Arabacı
asyncio.sleep() returns you a Future. When you yield from a future, your coroutine blocks, until the Future completes. In the meantime, event loop continutes to execute other things that are waiting to be executed. The Future returned from asyncio.sleep gets completed after specified seconds. 2014