Aug-12-2022, 02:31 PM
Hi!
I'm having trouble updating a label depending on a result from a function from one of the two processes I'm running. I'm trying using Queues, but can't make it work.
This is a simplified example of the code:
I tried different ways of importing Queue, but I always get errors. I'd appreciate any help or hint in what I'm doing wrong.
Thanks in advance!
I'm having trouble updating a label depending on a result from a function from one of the two processes I'm running. I'm trying using Queues, but can't make it work.
This is a simplified example of the code:
import multiprocessing as mp from tkinter import DISABLED, NORMAL, Label, LabelFrame, Tk import queue class Gui(object): def __init__(self, q): self.root = Tk() self.root.geometry('150x100') self.frameP1 = LabelFrame(self.root, text="Process1", font=("Helvetica", 14, "bold"), bd=0) self.frameP1.pack(padx=12) self.currentUserProcess1 = Label(self.frameP1, text="Current User p1", font=("Helvetica", 10, "bold")) self.currentUserProcess1.pack() self.frameP2 = LabelFrame(self.root, text="Process2", font=("Helvetica", 14, "bold"), bd=0) self.frameP2.pack() self.currentUserProcess2 = Label(self.frameP2, text="Current User p2", font=("Helvetica", 10, "bold")) self.currentUserProcess2.pack() self.root.after(100,self.CheckQueuePoll,q) def CheckQueuePoll(self, c_queue): try: str = c_queue(0) self.currentUserProcess2.configure(text=str) except queue.Empty: pass finally: self.root.after(100, self.CheckQueuePoll, q) def process1(): print("Executing process1") #doSomething def process2(): print("Executing process2") log = "Current User Process 2" q.put(log) def startProcesses(): global p1 global p2 p1 = mp.Process(target = process1) p2 = mp.Process(target = process2) p1.start() p2.start() def stopProcesses(): p1.terminate() p2.terminate() if __name__ == '__main__': q = mp.Queue() gui = Gui(q) p1 = mp.Process(target = process1, args=(q,)) p2 = mp.Process(target = process2, args=(q,)) p1.start() p2.start() gui.root.mainloop()This is giving me this error:
Error:TypeError: 'Queue' object is not callable
This happens when trying to execute "str = c_queue(0)" on CheckQueuePoll function.I tried different ways of importing Queue, but I always get errors. I'd appreciate any help or hint in what I'm doing wrong.
Thanks in advance!