Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import queue
  2. def task(name,queue):
  3. while not queue.empty():
  4. count = queue.get()
  5. print("Очередь",count)
  6. total = 0
  7. print("Name",name,'running')
  8. for x in range(count):
  9. total+=1
  10. yield
  11. print("Name",name,'total',total)
  12.  
  13. def main():
  14. work_queue = queue.Queue()
  15. for work in [15,10,5,2]:
  16. work_queue.put(work)
  17. tasks = [task('One',work_queue),task('Two',work_queue)]
  18.  
  19. done = False
  20. count = 0
  21.  
  22. while not done:
  23. for t in tasks:
  24. try:
  25. print('count',count)
  26. count = count + 1
  27. next(t)
  28. except StopIteration:
  29. print("Stop")
  30. tasks.remove(t)
  31. if len(tasks) == 0:
  32. done = True
  33.  
  34. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement