find a way not to wait for slowest proccess in tkinter

Viewed 29

i feel like i'm between a rock and a hard place. i want to write things to tkinter as quick as i can. right now i'm multiproccessing x jobs that can take a large range of times. I dont want to wait for my slowest process. when the quickest is finished, i want the answer to appear while we wait for the others.

So i tried to pass in my tkinter textbox to my proccess. However this throws a pickle error.

So what could i do to minimize the wait time instead of waiting for all processes to end.

# this is a minimal reproducable example
from tkinter import *
from multiprocessing import Process, Manager , freeze_support

def waste_time():
    time.sleep(random.randint(1, 30)) #  this represent 5-10 minutes of work from a chromedriver
    
def put_value_in_here(thing):
    waste_time()
    random_value = random.random()
    thing.delete('1.0',"end").insert('1.0', str(random_value)) # put answer in thing

def go():
    processes = []
    for a in answers:
        p1 = Process( target = put_value_in_here , args =  (a,) )
        processes.append(p1)
    for proc in processes:
        proc.start() ### this gives error if i pass tkinter object in to proccess
    for proc in processes:
        proc.join()

if __name__ == '__main__':
    freeze_support()
    window=Tk()
    canvas=Canvas(window, width=160, height=300)
    canvas.pack()
    anwers_1 = Text(window, height = 1, width = 8)
    anwers_1.pack()
    anwers_1.place(x=50, y=40);
    anwers_2 = Text(window, height = 1, width = 8)
    anwers_2.pack()
    anwers_2.place(x=50, y=100);
    answers = [anwers_1, anwers_2]
    B = Button(window, text ="go", command = go)
    B.place(x=50, y=150);
    window.mainloop();

edit: to clarify the problem)

On 1 hand, using multiproccessed dictionariares and passing data back that way means i have to wait for the slowest one with .join

but on the other hand the multiproccessed functions seem to have no way of having the tkinter objects passed into them, so the individual proccesses cant write to tkinter either.

0 Answers
Related