import threading
import pdb
class LockedIterator(object):
    def __init__(self, it):
        self.lock = threading.Lock()
        self.it = it.__iter__()

    def __iter__(self): return self

    def next(self):
        self.lock.acquire()
        try:
            return self.it.next()
        finally:
            self.lock.release()

gen = (x*2 for x in [1,2,3,4])
pdb.set_trace()
g2 = LockedIterator(gen)
print list(g2)

c323b92c90fe4e3a77a1c175968f9e09e33f0124
import threading
import pdb
class LockedIterator(object):
    def __init__(self, it):
        self.lock = threading.Lock()
        self.it = it.__iter__()

    def __iter__(self): return self

    def next(self):
        self.lock.acquire()
        try:
            return self.it.next()
        finally:
            self.lock.release()

gen = (x*2 for x in [1,2,3,4])
pdb.set_trace()
g2 = LockedIterator(gen)
print list(g2)
