Last active
January 6, 2025 03:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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