Blame view

3_no_locks.py 489 Bytes
444c887a   Lars Tiede   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #!/usr/bin/env python
  import asyncio
  import random
  
  finished_count = 0
  
  async def slow_op(n):
      global finished_count
      print("slow_op {} started".format(n))
      await asyncio.sleep(random.uniform(0.0, 1.0))
      finished_count += 1
      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())
  print("finished_count = {}".format(finished_count))