How to run multiple chrome in selenium python?

Viewed 199

I have 55 tasks. In this code, when it finished all 10 tasks, it will run 10 tasks more. However, I want to that when 1 in 10 tasks finish first, it will run more 1 task. Don't wait until 10 tasks finish. Does anyone know how to always run 10 tasks at a time until it finishes?

from selenium import webdriver
import time
import threading
from random import randrange
def login_outlook():
    chrome_option = webdriver.ChromeOptions()
    driver = webdriver.Chrome(executable_path='G:/chromedriver.exe', options=chrome_option)
    driver.set_window_rect(width=500, height=800)
    url = 'https://outlook.live.com/owa/'
    driver.get(url)

    driver.find_element_by_xpath('/html/body/header/div/aside/div/nav/ul/li[2]/a').click()
    time_wait = randrange(10, 30)
    time.sleep(time_wait)
    driver.close()


def run_thread(thread_amount):
    my_thread = []
    for i in range(thread_amount):
        my_thread.append(threading.Thread(target=login_outlook, args=[]))
    for t in my_thread:
        t.start()
    for t in my_thread:
        t.join()
mail_amount_can = 55
thread_amount = 10
while thread_amount < mail_amount_can:
    number = 0
    while number < int(thread_amount):
        run_thread(thread_amount)
        number+=1
    mail_amount_can = mail_amount_can - int(thread_amount)
number = 0
while number < int(thread_amount):
    run_thread(thread_amount)
    number+=1
0 Answers
Related