def main():

    src_path = '/vagrant/my_pictures/'
    workers_count = 5

    #we can use ArgumentParser but keeping things simple
    if len(sys.argv) >= 2:
        workers_count = int(sys.argv[1])
    print('Workers Count: %s' % (workers_count))

    #lets create a QueueClient object to connect to queue server to
    #get the `database_queue` proxy object as `outbox` queue
    q_client = QueueClient('database_queue', '', 12000, 'abc')
    outbox = q_client.get_queue()

    hasher = ImageHasher(src_path, outbox, workers_count)
    try:
        hasher.start()
    except KeyboardInterrupt:
        print('Got Shutdown. Stopping')
        hasher.shutdown.set()
        with hasher.empty:
            hasher.empty.notifyAll()
def main():
 
    src_path = '/vagrant/my_pictures/'
    workers_count = 5
 
    #we can use ArgumentParser but keeping things simple
    if len(sys.argv) >= 2:
        workers_count = int(sys.argv[1])
    print 'Workers Count: %s' % (workers_count)

    #lets create a QueueClient object to connect to queue server to 
    #get the `database_queue` proxy object as `outbox` queue 
    q_client = QueueClient('database_queue', '', 12000, 'abc')
    outbox = q_client.get_queue()
    
    hasher = ImageHasher(src_path, outbox, workers_count)
    try:
        hasher.start()
    except KeyboardInterrupt:
        print 'Got Shutdown. Stopping'
        hasher.shutdown.set()
        with hasher.empty: 
            hasher.empty.notifyAll()
        
    def insert(image_path, image_hash):
        _digest = md5.md5(image_path)
        image_id = str(_digest.hexdigest())
        query = 'INSERT INTO image (image_id, image_path, image_hash) VALUES (?, ?, ?)'
        self.con.execute(query, (image_id, image_path, image_hash,))
        self.con.commit()
        
    def process(self):
            
        self.setup_db()
        while not shutdown.isSet():
            try:
                image_path, image_hash = self.inbox.get()
                self.insert(image_path, image_hash)
            except sqlite3.IntegrityError as err:
                print err
                
    def stop(self):
        self.shutdown.set()
        
if __name__ == '__main__':
    
    client = QueueClient('database_queue', '', 12000, 'abc')
    inbox = client.get_queue()
    processor = DbProcessor('image.db', inbox)
    try:
        processor.start()
    except Keyboard:
        processor.stop()
        self.con.execute(query, (
            image_id,
            image_path,
            image_hash,
        ))
        self.con.commit()

    def process(self):

        self.setup_db()
        while not self.shutdown.isSet():
            try:
                image_path, image_hash = self.inbox.get()
                self.insert(image_path, image_hash)
            except sqlite3.IntegrityError as err:
                print(err)

    def stop(self):
        self.shutdown.set()


if __name__ == '__main__':

    client = QueueClient('database_queue', '', 12000, 'abc')
    inbox = client.get_queue()
    processor = DbProcessor('image.db', inbox)
    try:
        processor.start()
    except KeyboardInterrupt:
        processor.stop()