blob: 2f4970bcaca63e359cd36b5d8a1f53806dbe94dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import asyncio
async def pomme():
while True:
await asyncio.sleep(1)
print("pomme")
async def poire():
while True:
await asyncio.sleep(5)
print("poire")
async def main():
while True:
await pomme()
await poire()
async def ping(msg):
if msg > 5:
return
print("ping got:", msg)
await asyncio.sleep(1)
msg += 1
await pong(msg)
async def pong(msg):
if msg > 5:
return
print("pong got:", msg)
await asyncio.sleep(1)
msg += 1
await ping(msg)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(ping(1), pomme(), poire()))
|