replace ended threads in real time

instead of waiting for them all to finish
master
emamaker 2022-02-06 09:18:28 +01:00
parent 8c66703389
commit 2161f4ba01
1 changed files with 28 additions and 6 deletions

View File

@ -117,14 +117,36 @@ def launch_and_visit(use_tor, page_url, headless=False):
browser_manager.close_browser(driver, tor_process) browser_manager.close_browser(driver, tor_process)
if __name__ == "__main__": if __name__ == "__main__":
while True: NO_PROCESSES = 10
threads = [] threads = []
for i in range(0, 5): while True:
t1 = threading.Thread(target=launch_and_visit, args=(True, 'https://giangillorossi.altervista.org', True)) if len(threads) < NO_PROCESSES:
print(f"[BOT] Starting thread n.{len(threads)}/{NO_PROCESSES}")
t1 = threading.Thread(target=launch_and_visit, args=(False, 'https://giangillorossi.altervista.org', False))
t1.start() t1.start()
threads.append(t1) threads.append(t1)
for t in threads: i = 0
t.join() while i < len(threads):
# print(i)
if not (threads[i].is_alive()):
print(f"[BOT] Thread n.{i} has stopped, removing from list")
threads.pop(i)
else:
i += 1
# for i in range( 0, 5):
# t1 = threading.Thread(target=launch_and_visit, args=(True, 'https://giangillorossi.altervista.org', True))
# t1.start()
# threads.append(t1)
# for t in threads:
# t.join()