This would do:

loop.create_task(sleepy())
loop.call_later(1.0, loop.create_task, test())
loop.run_forever()

Think @coroutine as a thread which is started by loop.create_task() -
asyncio.async() in earlier versions. However, be aware of the difference
between a OS-level thread and nonpreemptive coroutines, please see:
http://en.wikipedia.org/wiki/Coroutine


BR,
Fantix
--
http://about.me/fantix

On Thu, Dec 25, 2014 at 6:10 PM, Mehdi Summer <[email protected]> wrote:

> Hi
> I'm trying to learn asyncio. so far i stuck on this situation: how can i
> run a coroutine between another one?
> Maybe i didn't get the concept of asyncio but please enlighten me!
> import asyncio
> import time
>
> loop = asyncio.get_event_loop()
>
> @asyncio.coroutine
> def sleepy():
>     print("before sleep", time.time())
>     yield from asyncio.sleep(3)
>     print("after sleep", time.time())
>
>
> @asyncio.coroutine
> def test():
>     print("this should run between!")
>
> Now how can i run test while sleepy already began and sleeping for 3
> seconds?
> I want output like:
>
> before sleep
>
> this should run between!
>
> after sleep
>
>
>

Reply via email to