简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM