def initTreadDict(self): for star in self.hotStarData: threadAdd = PandaTV(star['roomid']) threadAdd.setDaemon(True) #print('检测',star['roomid'],type(star),type(star['roomid'])) time.sleep(1) threadAdd.start() self.threadDict[threadAdd.getName()] = threadAdd print(self.roomiddict[threadAdd.getName()[6:]], '线程初始化') #panda thread name = "panda&" + roomid print(len(self.hotStarData), '个弹幕记录线程初始化')
def initTreadDict(self): for star in self.hotStarData: threadAdd = PandaTV(star['roomid']) threadAdd.setDaemon(True) #print('检测',star['roomid'],type(star),type(star['roomid'])) time.sleep(1) threadAdd.start() self.threadDict[threadAdd.getName()] = threadAdd print(self.roomiddict[threadAdd.getName()[6:]],'线程初始化') #panda thread name = "panda&" + roomid print(len(self.hotStarData),'个弹幕记录线程初始化')
def newThreadCreate(self): newThreadDict = dict() killTread = list() reThreadDict = dict() for star in self.hotStarData: newThreadDict[star['roomid']] = star['number'] # old thread checker for threadName, threadAdd in self.threadDict.items(): roomid = threadName[6:] #restart Dead thread if newThreadDict.pop(roomid, False) is not False: if threadAdd.isAlive() is False: print('need to recreat:', self.roomiddict[roomid], '线程状态为', threadAdd.isAlive()) # time.sleep(1) reThreadAdd = PandaTV(roomid) reThreadAdd.setDaemon(True) reThreadAdd.start() print('recreat:', self.roomiddict[roomid], '线程状态变为', reThreadAdd.isAlive()) reThreadDict[roomid] = reThreadAdd else: #kill down hot room threadAdd.exit() killTread.append(threadName) print('kill:', self.roomiddict[roomid], '线程状态变为', threadAdd.isAlive()) print('newthreaddict:', len(newThreadDict)) # del dead thread in self.threadict for deltread in killTread: self.threadDict.pop(deltread) # reload thread in self.threaddict for k, v in reThreadDict.items(): if self.threadDict.get(k): self.threadDict[k] = v # new thread creater if newThreadDict: for newName, hotNumber in newThreadDict.items(): threadAdd = PandaTV(newName) threadAdd.setDaemon(True) if self.threadDict.get('panda&' + str(newName), False) is False: # time.sleep(1) threadAdd.start() self.threadDict[threadAdd.getName()] = threadAdd print('creat:', self.roomiddict[newName], '新线程启动状态为', threadAdd.isAlive())
def newThreadCreate(self): newThreadDict = dict() killTread = list() reThreadDict = dict() for star in self.hotStarData: newThreadDict[star['roomid']] = star['number'] # old thread checker for threadName,threadAdd in self.threadDict.items(): roomid = threadName[6:] #restart Dead thread if newThreadDict.pop(roomid,False) is not False: if threadAdd.isAlive() is False: print('need to recreat:',self.roomiddict[roomid],'线程状态为',threadAdd.isAlive()) # time.sleep(1) reThreadAdd = PandaTV(roomid) reThreadAdd.setDaemon(True) reThreadAdd.start() print('recreat:',self.roomiddict[roomid],'线程状态变为', reThreadAdd.isAlive()) reThreadDict[roomid] = reThreadAdd else: #kill down hot room threadAdd.exit() killTread.append(threadName) print('kill:',self.roomiddict[roomid],'线程状态变为', threadAdd.isAlive()) print('newthreaddict:',len(newThreadDict)) # del dead thread in self.threadict for deltread in killTread: self.threadDict.pop(deltread) # reload thread in self.threaddict for k,v in reThreadDict.items(): if self.threadDict.get(k): self.threadDict[k] = v # new thread creater if newThreadDict: for newName,hotNumber in newThreadDict.items(): threadAdd = PandaTV(newName) threadAdd.setDaemon(True) if self.threadDict.get(self.platform+'&'+str(newName),False) is False: # time.sleep(1) threadAdd.start() self.threadDict[threadAdd.getName()] = threadAdd print('creat:',self.roomiddict[newName],'新线程启动状态为', threadAdd.isAlive())