В настоящее время у меня есть многопоточный python скрипт, который берет несколько URL-адресов и делает скриншот каждого из них. После того, как сделан каждый скриншот, я добавляю метку времени на скриншот с подушкой. Я понимаю, что после исследования в Google, Selenium не является потокобезопасным. В настоящее время я могу добиться многопоточности, создавая один драйвер на URL. Это на самом деле довольно медленно и довольно ресурсоемко.
Как я могу ускорить весь этот процесс? Я готов отказаться от Selenium и при необходимости взять новую библиотеку.
def retrieve_and_process_screenshots(url_list=None):
with concurrent.futures.ThreadPoolExecutor() as executor:
executor.map(multithreaded_screenshot, url_list)
def multithreaded_screenshot(url_item=None):
ff_options = Options()
for ff_option in config.firefox_options_config.split(","):
ff_options.add_argument(ff_option)
firefox_driver_path = "..\misc\geckodriver.exe"
driver = webdriver.Firefox(options=ff_options, executable_path=firefox_driver_path, service_log_path="..\logs\geckodriver.log")
driver.get(url_item)
time.sleep(2)
current_datetime = datetime.now().strftime(config.datetime_format)
image_filename = config.image_filename_format.replace("<DATETIME>", current_datetime)
image_output = os.path.join(config.image_output_directory, image_filename + ".png")
saved_screenshot = driver.get_screenshot_as_png()
driver.quit()
# Calls this function to do post processing on the image to add a timestamp
image_timestamp(image_output, saved_screenshot)
Большое спасибо!