def __init__(self, filename, queue, max): self.queue = queue self.max = max self.count = 0 self.file = DumpFileWriter(filename) self.file.open() self.running = True threading.Thread.__init__(self)
class EchoWriter(threading.Thread): def __init__(self, filename, queue, max): self.queue = queue self.max = max self.count = 0 self.file = DumpFileWriter(filename) self.file.open() self.running = True threading.Thread.__init__(self) def stop(self): self.running = False self.file.close() def run(self): while self.running: if self.max >= 0 and self.count >= self.max: print "Done writing observations." break try: obs = self.queue.get(True, 1.0) self.count += 1 if self.count % 100 == 0: print "Wrote %d observations to file" % self.count self.file.writeObservation(obs) except: continue self.stop() sys.exit(0)
class EchoWriter(threading.Thread): def __init__(self, filename, queue, max): self.queue = queue self.max = max self.count = 0 self.file = DumpFileWriter(filename) self.file.open() self.running = True threading.Thread.__init__(self) def stop(self): self.running = False self.file.close() def run(self): while self.running: if self.max >= 0 and self.count >= self.max: print "Done writing observations." break try: obs = self.queue.get(True,1.0) self.count += 1 if self.count % 100 == 0: print "Wrote %d observations to file" % self.count self.file.writeObservation(obs) except: continue self.stop() sys.exit(0)
## Create an ObservationsManager for the Data Source to write to ##------------------------------------------------------------------------- if WindowSize > 0: obsman = Dynamic.ObservationsManager(WindowSize) else: obsman = Static.ObservationsManager() obsman.start() ## Define the observations queue based on whether or not dumping was set ##------------------------------------------------------------------------- if DumpObservationsFile: DumpQueue = Queue() ObservationsQueue = (obsman, DumpQueue) DumpWriter = DumpFileWriter(filename=DumpObservationsFile, queue=DumpQueue) DumpWriter.open() DumpWriter.start() else: ObservationsQueue = obsman ## Instantiate the Data Source ##------------------------------------------------------------------------- if ObservationFile: DataSource = DumpFileReader(queue=ObservationsQueue,filename=ObservationFile) elif SimulatePositions: DataSource = Simulator(queue=ObservationsQueue, cali=CalibrationData, tag=TagID, movement=SimulatePositions, mobility=SimulateMobility) else: DataSource = ReceiverServer(queue=ObservationsQueue,t=ReceiverRate,n=ReceiverSamples)