Advertisement
ur001

Untitled

Jan 30th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. class Transaction(object):
  2.     def __init__(self):
  3.         self.callbacks = []
  4.  
  5.     def on_commit(self, callback):
  6.         self.callbacks.append(callback)
  7.  
  8.     def commit(self):
  9.         for callback in self.callbacks:
  10.             callback()
  11.  
  12.  
  13. transaction = Transaction()
  14.  
  15.  
  16. def update_guide_exp_visibility(exp_id):
  17.     print "update_guide_exp_visibility({})".format(exp_id)
  18.  
  19. update_guide_exp_visibility.delay = update_guide_exp_visibility
  20.  
  21. def test():
  22.     for exp_id in range(1, 11):
  23.         transaction.on_commit(
  24.             lambda: update_guide_exp_visibility.delay(exp_id)
  25.         )    
  26.  
  27. test()  
  28. transaction.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement