Python Forum
Tkinter + Multiprocessing startmap makes UI Freeze
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter + Multiprocessing startmap makes UI Freeze
#1
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
Reply
#2
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()?
Reply
#3
Thanks @deanhystad i figured it out.
Reply
#4
What did you figure out?
Reply
#5
Sorry for delay reply @deanhystad, i use itertools.product
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What a difference print() makes Mark17 2 580 Oct-20-2023, 10:24 PM
Last Post: DeaD_EyE
  Upgrade makes Code Error kucingkembar 6 3,118 Jul-28-2022, 06:44 PM
Last Post: kucingkembar
  mpv window freeze before video end rfeyer 18 7,117 Mar-09-2021, 06:12 PM
Last Post: rfeyer
  Install Python 3.8 for EduPython and Cx-Freeze mederic39 1 1,799 Jul-24-2020, 01:24 PM
Last Post: Larz60+
  Cx Freeze to exe - HELP WBPYTHON 5 3,884 Apr-09-2020, 01:34 PM
Last Post: WBPYTHON
  A software freeze ! HELP ! redorc15 1 1,796 Oct-10-2019, 10:54 PM
Last Post: Larz60+
  help! this 'for' loop makes me crazy lerner50 5 2,946 Jul-09-2019, 03:39 PM
Last Post: perfringo
  cx-Freeze exe doesn't work ammann 1 4,324 Mar-19-2018, 10:58 AM
Last Post: buran
  The number of object makes code slower? fig0 1 2,522 Jan-25-2018, 11:16 PM
Last Post: Gribouillis
  Pyusb freeze when using Dev.read(nr,nr,timeout=1000) bojane 3 7,541 Jan-11-2017, 10:17 AM
Last Post: bojane

Forum Jump:

User Panel Messages

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