def start(): thread_list = [] total = redisutil.total(common.KEY) ts = common.getTime() page_size = 0 thread_total = 5 if total <= 5: page_size = 1 thread_total = total else: page_size = total / 5 for t in range(1, thread_total + 1): start = (t - 1) * page_size + 1 end = t * page_size + 1 name = "a" + str(t) t = threading.Thread(target=enter, name=name, kwargs={ "start": start, "end": end, "ts": ts }) thread_list.append(t) for t in thread_list: t.start() for t in thread_list: t.join() print("all thread over")
def start(): try: print("即将启动解析列表程序") parse_list.start() # 睡眠5分钟后启动 print("即将启动解析视频程序") #time.sleep(2) parse_src.start() # time.sleep(3) end = int(redisutil.total(common.KEY_SRC)) download_thread.enter(start=1, end=end) except Exception as e: print(e) print('整个程序出错')
if not r'http://v2' in src: download(src) print(threading.current_thread().name, " 下载 ", src, " 完成, 从redis 删除") client.lrem("91_src", 0, a) redisutil.add(a, common.KEY_ALREADY_DOWNLOAD) else: print('无法下载的url-v2') client.lrem("91_src", 0, a) redisutil.add(a, common.KEY_ALREADY_DOWNLOAD) if __name__ == "__main__": # thread_list = [] # for i in range(1, 6): # start = (i - 1) * 4000 + 1 # end = i * 4000 + 1 # t = threading.Thread(target=enter, name="a" + str(i),kwargs={'start':start, 'end':end}) # thread_list.append(t) # for t in thread_list: # t.start() # for t in thread_list: # t.join() # print("over") end = int(redisutil.total(common.KEY_SRC)) enter(start=1, end=end)