1

I have all 50 chrome must run. I want to always run 5 chrome at the same time. If 1 in 5 chrome closes first, it will run 1 chrome new. Until 50 chrome finished.

Example: 5 chrome are running. If chrome 3 closes first, chrome 6 will run. So it always run 5 chrome at the same time.

How can I do it?

run_chrome = 50
thread = 5
def run_thread(thread_amount):
    my_thread = []
    for i in range(thread_amount):
        my_thread.append(threading.Thread(target=run_chrome_browser, args=[]))
    for t in my_thread:
        t.start()
    for t in my_thread:
        t.join()
while thread < run_chrome:
    run_thread(thread)
    run_chrome = run_chrome - thread
run_thread(run_chrome)
1
  • use threading, also provide what you have tried already, provide a minimal reproducible example and ask a more specific question Commented Aug 24, 2021 at 9:18

1 Answer 1

2

Thread-pool is one of solutions.

import time

from concurrent.futures import ThreadPoolExecutor

pool = ThreadPoolExecutor(max_workers=5)

def chrome_app_func(i):
    print(f"Fake chrome app: {i}")
    time.sleep(10)
    print(f"Fake chrome app: {i} -- finished")


for i in range(50):
    pool.submit(chrome_app_func, i)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.