Blame view

1_just_some_coros.py 363 Bytes
444c887a   Lars Tiede   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #!/usr/bin/env python
  import asyncio
  import random
  
  async def slow_op(n):
      print("slow_op {} started".format(n))
      await asyncio.sleep(random.uniform(0, 2))
      print("slow_op {} complete".format(n))
  
  async def main():
      await asyncio.wait([
          slow_op(i) for i in range(10)
          ])
  
  loop = asyncio.get_event_loop()
  loop.run_until_complete(main())