Python Forum
Tkinter + Multiprocessing startmap makes UI Freeze - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Tkinter + Multiprocessing startmap makes UI Freeze (/thread-38138.html)



Tkinter + Multiprocessing startmap makes UI Freeze - sunny9495 - Sep-07-2022

Hi,

the UI freezes when apply the following code to the tkinter

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from utilities.dictionary import Predefined
import time
import multiprocessing
from itertools import product

x = ['http://google.com', 'http://yahoo.com', 'http://bing.com']
y = ['weight loss tips', 'weight loss plan', 'weight loss diet', 'weight loss workouts', 'weight loss plan for a month', 'weight loss']

def merge_names(a, b):
    print(a)
    print(b)
    # return '{} & {}'.format(a, b)
    options = Options()
    options.binary_location = r'drivers/browser/chrome.exe'
    driver = webdriver.Chrome(executable_path=r'drivers/chromedriver.exe', options=options)
    driver.get(a)
    do = Predefined(driver)
    time.sleep(5)
    do.typeinput('//input[@name="q"] | //input[@name="p"]', b)
    time.sleep(10)
    driver.close()
    driver.quit()

if __name__ == '__main__':
    with multiprocessing.Pool(processes=3) as pool:
        results = pool.starmap(merge_names, product(x, y))
Any Help Would be Appreciated, Thanks


RE: Tkinter + Multiprocessing startmap makes UI Freeze - deanhystad - Sep-07-2022

Tkinter freezes because you are sleeping 270 (15 * 18) seconds. "But wait!" you say, "I am doing multi-processing!". That may be true, but starmap() blocks, waiting for all the processes (which are executing on different processors) to complete. I don't know how many processes you can run in parallel, but if it is 3, that still means waiting 90 seconds (or more) for everything to finish. Can you use starmap_async()?


RE: Tkinter + Multiprocessing startmap makes UI Freeze - sunny9495 - Sep-08-2022

Thanks @deanhystad i figured it out.


RE: Tkinter + Multiprocessing startmap makes UI Freeze - deanhystad - Sep-08-2022

What did you figure out?


RE: Tkinter + Multiprocessing startmap makes UI Freeze - sunny9495 - Nov-13-2022

Sorry for delay reply @deanhystad, i use itertools.product