threading
import os import multiprocessing 1、获取Chromedriver驱动动态路径 webdriver.Chrome(executable_path=os.path.join(os.getcwd(), "chromedriver.exe")) 2、等待特地(label)网页元素加载完毕,返回真 is_disappeared = WebDriverWait(dr, 30, 1, ignored_exceptions=TimeoutException).until(lambda x: x.find_element_by_id("label").is_displayed()) 3、多进程 if __name__ == '__main__': multiprocessing.freeze_support() pool = multiprocessing.Pool(processes=4) for i in range(2): pool.apply_async(func,args=(args,)) pool.close() pool.join() 4、多线程 if __name__ == '__main__': mutex = threading.RLock() task_list = [] for i in range(3) t. = threading.Thread(target=main_func, args=(args1, args2, mutex,)) task_list.append(t) for i in task_list: i.start() for i in task_list: i.join()
import threading class MyThread(threading.Thread): def __init__(self, para): threading.Thread.__init__(self) self.para = para def operation(self, para): print("deal with para", para) def run(self): self.operation(self.para) if __name__ == "__main__": paras = ["1", "2"] threads = [] for para in paras: threads.append(MyThread(para)) for thread in threads: thread.start() for thread in threads: thread.join()