Aug-12-2022, 07:40 PM
(Aug-12-2022, 07:04 PM)woooee Wrote: Pass gui.currentUserProcess 1 or 2 to the process as an arg. Each process can then update it.
I tried it. This is the code I got, in case I did something wrong:
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() def process1(): print("Executing process1") #doSomething def process2(currentUserProcess2): print("Executing process2") log = "Current user process 2" currentUserProcess2.configure(text=log) def startProcesses(): global p1 global p2 p1 = mp.Process(target = process1, args=(gui.currentUserProcess2,)) p2 = mp.Process(target = process2, args=(gui.currentUserProcess2,)) 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=(gui.currentUserProcess2,)) p2 = mp.Process(target = process2, args=(gui.currentUserProcess2,)) p1.start() p2.start() gui.root.mainloop()I got this:
Error:Traceback (most recent call last):
File "c:\Users\User1\Desktop\MultiTkinter\main.py", line 63, in <module>
p1.start()
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
reduction.dump(process_obj, to_child)
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle '_tkinter.tkapp' object
PS C:\Users\User1\Desktop\MultiTkinter> Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 107, in spawn_main
new_handle = reduction.duplicate(pipe_handle,
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\multiprocessing\reduction.py", line 79, in duplicate
return _winapi.DuplicateHandle(
PermissionError: [WinError 5] Access is denied
I deleted CheckQueuePoll function as I understand it wouldn't be needed if I'm passing "gui.CurrenUserProcess2" in the parameters.