Colbearism
Colbearism

Reputation: 3

pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup module on builtins failed

I am new in python and I am trying to use multiprocessing within a class. I have tried to do this with threading and it worked, but when I changed it into multiprocessing, it came up with the errors shown below. The reason why I am trying to use multiprocessing instead of threading is that multiprocessing has .terminate() while threading does not. Please help me, thank you!

Code:

class PageMenu(tk.Frame):   


    def __init__(self, parent, controller):

        def startRolling(times):     
            theProcess = multiprocessing.Process(target = fa.main, args = (fa.roles[choice.get()], times))
            theProcess.start()
        tk.Frame.__init__(self, parent)
        textFeed = tk.IntVar()
        textField = tk.Entry(self, textvariable = textFeed)
        textField.place(x = 165, y = 170)

        button7 = tk.Button(self, text="=-=-=Start=-=-=",  command = lambda: startRolling(textFeed.get()),font = LARGE_FONT)
        button7.place(x = 165, y = 200)

Errors: _pickle.PicklingError: Can't pickle : attribute lookup module on builtins failed

the full version of the errors is in the link below

enter image description here

Upvotes: 0

Views: 1342

Answers (1)

user149341
user149341

Reputation:

multiprocessing is not a substitute for threads.

Code running in processes created with multiprocessing runs in a separate process from the process which created it. As such, it cannot access objects related to the Tk GUI; those objects are only valid in the parent process.

If you need to terminate a thread, use a condition variable to notify it that it's time to stop.

Upvotes: 1

Related Questions