def make_source items class TaskSource object def __init__ self items

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def make_source(items):
class TaskSource(object):
def __init__(self, items):
self.lock = threading.Lock()
self.gen = itertools.chain(items, itertools.repeat(None))
def get(self):
self.lock.acquire()
item = self.gen.next()
self.lock.release()
return item
return TaskSource(items)