SHARE
TWEET

Untitled

a guest Jan 8th, 2012 174 Never
  1. # in stackless python or pypy
  2. def repeat(item):
  3.     i = 0
  4.     while True:
  5.         yield i, item
  6.         i += 1
  7.  
  8. import pickle
  9. gen = repeat('foo')
  10. print gen.next() # (0, 'foo')
  11. dumped = pickle.dumps(gen)
  12. # and in another machine
  13. gen = pickle.loads(dumped)
  14. print gen.next() # (1, 'foo')
RAW Paste Data
Top