Skip to content

Instantly share code, notes, and snippets.

@wh1t3h47
Last active January 6, 2025 03:32
Show Gist options
  • Save wh1t3h47/f894d37b134474010a10a019d43b4233 to your computer and use it in GitHub Desktop.
Save wh1t3h47/f894d37b134474010a10a019d43b4233 to your computer and use it in GitHub Desktop.
Using Drission page - concurrency with threads/ thread pools, no locking, working and tested
'''
multiple threads / tabs concurrency drission
This works when twisted being used, but not the most recommended method, leaving note here for "backup" of a tested method
'''
from typing import Callable, Iterable, Optional, Tuple, cast
from concurrent.futures import ThreadPoolExecutor
from DrissionPage import ChromiumPage
def open_tab(self, driver: ChromiumPage, link: str) -> Tuple[str]:
tab = driver.new_tab(link, background=True)
tab.wait.doc_loaded()
# ...
with ThreadPoolExecutor(max_workers=4) as executor:
driver = ChromiumPage()
results = executor.map(lambda href: self.open_tab(driver, href), batch)
return list(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment