cursor.close()
            self.connection.commit()
        except Exception as inst:
            print type(inst)     # the exception instance
            print inst.args      # arguments stored in .args
            print inst           # __str__ allows args to printed directly

        if not self.queue.empty():
            self.classifier = self.queue.get()
            return False # force a restart of the stream
        else:
            return True

    def on_error(self, status):
        print status

if __name__ == '__main__':
    query_set = dict()
    query_set['keyword'] = ['obama', 'usa']
    query_set['user'] = ['326698989', '326802887', '314575095', '16573941', '15033883']
    queue = Queue.Queue()
    trainer = AdaptiveTweetClassifierTrainer(queue)
    l = TweetStreamListener(trainer, queue)
    auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    stream = Stream(auth, l)

    while True:
        stream.filter(follow=query_set['user'], track=query_set['keyword'])
        query_set = trainer.get_query_set()
        print "Model loading"