def perThread(queue):
    from DataPoint import DataPoint, Session
    session = Session()

    while True:
        try:
            target1, target2, node = queue.get()
            #print target1, target2, node
            result = query_latency(target1, target2, node)
            success = False
            if result:
                end_time, start_time, ping_times, address = result
                if end_time and start_time and ping_times and address:
                    success = True
            else:
                end_time = start_time = ping_times = address = None
            point = DataPoint(target1[0], target2[0], target1, target2, start_time, end_time, ping_times, address, node.host, success)
            while True:
                try:
                    session.add(point)
                    session.commit()
                    break
                except Exception, e:
                    print e
                    session.close()
                    session = Session()
        except Exception, e:
            outputException(e)
 def connect(self):
     try:
         self.connectPL()
     except Exception, e:
         
         try:
             self.restartPL()
             self.connectPL()
         except Exception, e:
             outputException(e)  
             self.connected = False
        def wrapped(self, *args, **kwargs):
            if not self.connected:
                self.connect()

            if self.connected:
                try:
                    return fn(self, *args, **kwargs)
                except Exception, e:
                    outputException(e)
                    self.connected = False
                    try:
                        self.connect()
                        return fn(self, *args, **kwargs)
                    except Exception, e:
                        outputException(e)
                        self.connected = False
                        return None