Mar-26-2022, 05:36 AM
I have coded a simple program of run through the list, but apply_sync isn't waiting until the list is complete, here is the code
Any help would be appreciated.
Thank you
import itertools
import multiprocessing
from multiprocessing import Pool
import time
from tkinter import *
from tkinter import ttk
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import os
from tkinter import messagebox
x= ['annah', 'reena', 'jermy', 'sunny', 'chinni']
def next_name(name):
options = Options()
options.binary_location = r'drivers/Browser/chrome.exe'
driver = webdriver.Chrome(executable_path=r'drivers/chromedriver.exe', options=options)
driver.get('http://google.com')
time.sleep(2)
driver.find_element(By.XPATH, '//input[@name="q"]').send_keys(name)
time.sleep(2)
driver.find_element(By.XPATH, '//input[@name="q"]').send_keys(Keys.ENTER)
time.sleep(3)
driver.close()
def start():
global y
y = Pool(processes=2)
for usr in itertools.zip_longest(x):
y.apply_async(next_name, args=(usr, ))
#messagebox has to popup when list is completed
messagebox.showinfo("Sample Program", "List Completed")
def stop():
y.terminate()
os.system("taskkill /F /IM chromedriver.exe /T")
root = Tk()
startbtn = ttk.Button(root, text="start", command=start)
startbtn.pack()
stopbtn = ttk.Button(root, text="stop", command=stop)
stopbtn.pack()
root.geometry('300x300')
if __name__ == '__main__':
multiprocessing.freeze_support()
root.mainloop()I just want the program to show message box when list was completed. Any help would be appreciated.
Thank you
