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),'个弹幕记录线程初始化')
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())
# from mulpro import God # from pandaspider import PandaSpider from pandaTV import PandaTV # from douyuspider import DouyuSpider from douyuTV import DouyuTV from singler import DouyuGuard, PandaGuard, God import sys if __name__ == '__main__': cmd = sys.argv[1] if len(sys.argv) > 1 else 'None' rid = sys.argv[1] if len(sys.argv) > 1 else None if cmd == 'douyuGuard': God(DouyuGuard()).run() elif cmd == 'pandaGuard': God(PandaGuard()).run() elif cmd == 'douyuDanmu': roomid = rid if len(rid) > 1 else '48699' DouyuTV(roomid, show=True).start() elif cmd == 'pandaDanmu': roomid = rid if len(rid) > 1 else '66666' PandaTV(roomid, show=True).start() elif cmd == 'douyuNoGuard': DouyuGuard.run() elif cmd == 'pandaNoGuard': PandaGuard.run() else: print('Command is not found')
import sys from douyuTV import DouyuTV if __name__=='__main__': idolid= sys.argv[1] if len(sys.argv)>1 else 'board' douyu=DouyuTV(idolid) douyu.show() #python3 douyuTVDanmu.py 16789