Guest User

Untitled

a guest
Oct 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. from queue import Queue
  2.  
  3. class Cudo:
  4. def __init__(self, queue, initial_state):
  5. self.queue = queue
  6. self.state = initial_state
  7.  
  8. def __call__(self):
  9. while not queue.empty():
  10. self.state = queue.get()
  11. print(self.state)
  12.  
  13. queue = Queue()
  14.  
  15. # cudo'll be set initially to these values
  16. cudo = cudo(queue, {'k' : 1, 't_i' : 0, 't_d' : 0})
  17. cudo() # cudo keeps the value
  18. cudo() # nothing changed - cudo keeps old values
  19.  
  20. queue.put({'k' : 6, 't_i' : 6, 't_d' : 6})
  21. cudo() # cudo prints new values
  22. cudo() # cudo prints same values as above
  23.  
  24.  
  25. # value will be ignored by cudo
  26. queue.put({'k' : 1, 't_i' : 2, 't_d' : 3})
  27. # actual value which will be used by cudo
  28. queue.put({'k' : 4, 't_i' : 5, 't_d' : 6})
  29.  
  30. cudo()
  31. cudo()
Add Comment
Please, Sign In to add comment