コード例 #1
0
	def alg_start(self):
		printh('Algorithm', 'Algorithm is now online...', 'green')
		#3 Thread Handle Init
		self.applyHandle = threading.Thread(target=self.applyThread, args=(5.0,))
		self.applyHandle.setDaemon(True)
		self.applyHandle.start()
		pass
コード例 #2
0
    def processThread(self):
        redist_fp = open(path.join('Files', self.fhash), 'w+b')
        #redist_fp.fillin(chr(0), self.size) #not needed
        tot = self.numB
        seq_map = [time.time()] * self.numB

        while not self.paused and tot > 0:
            itert, ptr, maxB = 0, 0, 0
            index = ptr % self.bsize
            while ptr <= self.numB:
                thisB = self.ringBuffer[index][0]
                if seq_map[ptr] != -1:
                    if thisB == ptr:
                        redist_fp.seek(ptr * self.length)
                        redist_fp.write(self.ringBuffer[index][1])
                        maxB = thisB  #update maxB for this iteration
                        tot -= 1
                        seq_map[ptr] = -1
                        pass
                    elif time.time() - seq_map[ptr] > 1.0:  #timeout with 1s
                        self.fb_q.put(build_control(0, 'NAK', ptr))
                        seq_map[ptr] = time.time()
                        pass
                    pass
                ptr += 1
                pass
            print('iteration %d: %d' % (itert, maxB))
            pass

        redist_fp.truncate(self.size)  #remove extra zeros
        redist_fp.close()
        printh('Aggregator', 'End of File', 'red')
        pass
コード例 #3
0
	def run(self):
		self.alg_start()
		try:
			while True:
				if not self.fb_q.empty():
					frame = fb_q.get_nowait()
					#self.countup(frame)
					pass
				pass
		except Exception as e:
			printh('Algorithm', e, 'red') #for debug
			pass
		finally:
			self.alg_exit()
コード例 #4
0
	def readThread(self):
		while not self.paused:
			interval = self.length / self.speed
			try:
				data = self.data.data_read_op(self.length)
				if not data:
					self.paused = True
					raise Exception('End of File')
					pass
				else:
					self.buffer.put_nowait(data)
					#print('Source Data: %s'%(data)) #for debug
					pass
				sleep(interval)
			except Exception as e:
				if not e.message=='':
					printh('read-thread', e, 'red')
			pass
		pass
コード例 #5
0
	def alg_exit(self):
		printh('Algorithm', "Now exit...", 'red')
		exit()
		pass
コード例 #6
0
	def stop(self):
		self.paused = True
		if self.sourceHandle.is_alive():
			self.sourceHandle.join()
		printh('Source %d'%self.task_id, 'Stream stopped...', 'red')
		pass
コード例 #7
0
	def start(self):
		self.paused = False
		self.thread_init()
		self.sourceHandle.start()
		printh('Source %d'%self.task_id, 'Now start...', 'green')
		pass