Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from queue import Queue
- class Cudo:
- def __init__(self, queue, initial_state):
- self.queue = queue
- self.state = initial_state
- def __call__(self):
- while not queue.empty():
- self.state = queue.get()
- print(self.state)
- queue = Queue()
- # cudo'll be set initially to these values
- cudo = cudo(queue, {'k' : 1, 't_i' : 0, 't_d' : 0})
- cudo() # cudo keeps the value
- cudo() # nothing changed - cudo keeps old values
- queue.put({'k' : 6, 't_i' : 6, 't_d' : 6})
- cudo() # cudo prints new values
- cudo() # cudo prints same values as above
- # value will be ignored by cudo
- queue.put({'k' : 1, 't_i' : 2, 't_d' : 3})
- # actual value which will be used by cudo
- queue.put({'k' : 4, 't_i' : 5, 't_d' : 6})
- cudo()
- cudo()
Add Comment
Please, Sign In to add comment