Advertisement
rfmonk

collections_deque_both_ends.py

Jan 9th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import collections
  5. import threading
  6. import time
  7.  
  8. candle = collections.deque(xrange(5))
  9.  
  10.  
  11. def burn(direction, nextSource):
  12.     while True:
  13.         try:
  14.             next = nextSource()
  15.         except IndexError:
  16.             break
  17.         else:
  18.             print '%8s: %s' % (direction, next)
  19.             time.sleep(0.1)
  20.     print '%8s done' % direction
  21.     return
  22.  
  23. left = threading.Thread(target=burn, args=('Left', candle.popleft))
  24. right = threading.Thread(target=burn, args=('Right', candle.pop))
  25.  
  26. left.start()
  27. right.start()
  28.  
  29. left.join()
  30. right.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement