class Producer(threading.Thread): """ Produces random integers to a list """ def __init__(self, integers, condition): """ Constructor. @param integers list of integers @param condition condition synchronization object """ threading.Thread.__init__(self) self.integers = integers self.condition = condition def run(self): """ Thread run method. Append random integers to the integers list at random time. """ while True: integer = random.randint(0, 256) self.condition.acquire() print 'condition acquired by %s' % self.integers.append(integer) print '%d appended to list by %s' % (integer, print 'condition notified by %s' % self.condition.notify() print 'condition released by %s' % self.condition.release() time.sleep(1)