Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit 880e108

Browse files
authored
Fix issues in hello_clock.py (#29)
Closes issue #28 by making both coroutines exit after ~10 minutes.
1 parent c43065c commit 880e108

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

examples/hello_clock.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import asyncio
22

33

4+
async def print_every_minute():
5+
"Print minutes for ten minutes"
6+
for i in range(10):
7+
await asyncio.sleep(60)
8+
print(i, 'minute')
9+
10+
411
async def print_every_second():
5-
"""Print seconds"""
6-
while True:
12+
"Print seconds for ten minutes"
13+
for i in range(10 * 60):
714
for i in range(60):
815
print(i, 's')
916
await asyncio.sleep(1)
1017

1118

12-
async def print_every_minute():
13-
for i in range(1, 10):
14-
await asyncio.sleep(60)
15-
print(i, 'minute')
16-
17-
1819
loop = asyncio.get_event_loop()
1920
loop.run_until_complete(
20-
asyncio.gather(print_every_second(),
21-
print_every_minute())
21+
asyncio.gather(print_every_minute(),
22+
print_every_second())
2223
)
2324
loop.close()

0 commit comments

Comments
 (0)