예제 #1
0
 def initTreadDict(self):
     # pdb.set_trace()
     for star in self.hotStarData:
         threadAdd = DouyuTV(star['roomid'])
         threadAdd.setDaemon(True)
         # print('检测',star['roomid'],type(star),type(star['roomid']))
         time.sleep(1)
         threadAdd.start()
         self.threadDict[threadAdd.getName()] = threadAdd
         # pdb.set_trace()
         print(self.roomiddict[threadAdd.getName()[6:]],'线程初始化')
         #douyu thread name = "douyu&" + roomid
     print(len(self.hotStarData),'个弹幕记录线程初始化')
예제 #2
0
    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 = DouyuTV(roomid)
                    reThreadAdd.setDaemon(True)
                    reThreadAdd.start()
                    print('recreat:',self.roomiddict[roomid],'线程状态变为',
                        reThreadAdd.isAlive())
                    reThreadDict[roomid] = reThreadAdd
                    # raise Exception('father 666')
            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 = DouyuTV(newName)
                threadAdd.setDaemon(True)
                if self.threadDict.get('douyu&'+str(newName),False) is False:
                    # time.sleep(1)
                    threadAdd.start()
                    self.threadDict[threadAdd.getName()] = threadAdd
                    print('creat:',self.roomiddict[newName],'新线程启动状态为',
                        threadAdd.isAlive())