[英]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. 我是python的新手,正在尝试在一个类中使用多重处理。 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.
我尝试使用多处理而非线程的原因是,多处理具有.terminate(),而线程没有。 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 错误:_pickle.PicklingError:无法酸洗:内置的属性查找模块失败
the full version of the errors is in the link below 错误的完整版本在下面的链接中
multiprocessing
is not a substitute for threads. multiprocessing
不能替代线程。
Code running in processes created with multiprocessing
runs in a separate process from the process which created it. 在通过
multiprocessing
处理创建的进程中运行的代码在与创建它的进程不同的进程中运行。 As such, it cannot access objects related to the Tk GUI; 因此,它无法访问与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. 如果需要终止线程,请使用条件变量来通知该线程该停止了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.