Python Forum
Python multiprocessing Pool apply async wait for process to complete
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python multiprocessing Pool apply async wait for process to complete
#1
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

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
Reply


Messages In This Thread
Python multiprocessing Pool apply async wait for process to complete - by sunny9495 - Mar-26-2022, 05:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is this a multiprocessing bug in Python - or am I doing something wrong? haimat 1 1,239 Oct-18-2023, 06:07 AM
Last Post: absalom1
  queue for async function python telegram.ext noctious 0 1,641 Jun-11-2023, 02:58 PM
Last Post: noctious
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 857 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  Question about Creating an Automated Process in Python Supratik1234 0 777 Jan-13-2023, 08:29 PM
Last Post: Supratik1234
  python multiprocessing help -- to extract 10 sql table into csv mg24 3 1,438 Nov-20-2022, 11:50 PM
Last Post: mg24
  Multiprocessing Pool Multiple Instances How to Kill by Pool ID sunny9495 0 786 Nov-16-2022, 05:57 AM
Last Post: sunny9495
  python multiprocessing to download sql table mg24 5 1,537 Oct-31-2022, 03:53 PM
Last Post: Larz60+
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,082 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Wait til a date and time KatManDEW 2 1,460 Mar-11-2022, 08:05 PM
Last Post: KatManDEW
  wait for the first of these events Skaperen 4 2,018 Mar-07-2022, 08:46 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020