pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup module on builtins failed
pickle.PicklingError: Can't pickle <class 'module'>: attribute lookup module on builtins failed
我是 python 的新手,我正在尝试在 class 中使用多处理。我曾尝试用线程来做到这一点并且它成功了,但是当我将它改为多处理时,它出现了如下所示的错误。我尝试使用多处理而不是线程的原因是多处理有 .terminate() 而线程没有。请帮帮我,谢谢!
代码:
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)
错误:
_pickle.PicklingError: 无法腌制:内置属性查找模块失败
错误的完整版本在下面link
enter image description here
multiprocessing
不能替代线程。
使用 multiprocessing
创建的进程中的代码 运行 在与创建它的进程不同的进程中运行。因此,它无法访问与 Tk GUI 相关的对象;这些对象仅在父进程中有效。
如果您需要终止线程,请使用条件变量通知它该停止了。
我是 python 的新手,我正在尝试在 class 中使用多处理。我曾尝试用线程来做到这一点并且它成功了,但是当我将它改为多处理时,它出现了如下所示的错误。我尝试使用多处理而不是线程的原因是多处理有 .terminate() 而线程没有。请帮帮我,谢谢!
代码:
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)
错误: _pickle.PicklingError: 无法腌制:内置属性查找模块失败
错误的完整版本在下面link
enter image description here
multiprocessing
不能替代线程。
使用 multiprocessing
创建的进程中的代码 运行 在与创建它的进程不同的进程中运行。因此,它无法访问与 Tk GUI 相关的对象;这些对象仅在父进程中有效。
如果您需要终止线程,请使用条件变量通知它该停止了。