summaryrefslogtreecommitdiff
path: root/examples/hello_coroutine.py
blob: b9347aa893534acff413137e1ff78bff5a7a0070 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""Print 'Hello World' every two seconds, using a coroutine."""

import asyncio


@asyncio.coroutine
def greet_every_two_seconds():
    while True:
        print('Hello World')
        yield from asyncio.sleep(2)


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(greet_every_two_seconds())
    finally:
        loop.close()