def POISocketSender(self): try: print "\tin POISocketSender" messageNum = 1 while self.close == False: while self.sendingData != True and self.close == False: time.sleep(0.1) while self.sendingData == True and self.close == False: # TODO only sent requested types syncTime = time.time() POIToSend = [(uid, point.toDict()) for uid, point in POIelements.items() if point.getTimestamp() >= self.lastSync] # and point.type in self.overlays] jsonPOI = json.dumps({"POI":dict(POIToSend)}) print "\tSS message #{0} : {1} ({2} points, connection {3}, lastSync {4})".format( messageNum, "not shown", len(POIToSend), self.connectionNumber, self.lastSync) self.lastSync = syncTime self.clientsocket.sendall(jsonPOI + "\n") messageNum += 1 time.sleep(3.875 + (random.random() / 4.0)) # 4 second average pause except KeyboardInterrupt: print "\tPSS broke by KeyboardInterrupt (%d)" %(self.connectionNumber) except Exception as e: print "\tPSS broke by some random exception or interrupt (%d)" %(self.connectionNumber) print e