简体   繁体   English

pickle.PicklingError:不能腌制 <class 'module'> :内建属性查找模块失败

[英]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 错误的完整版本在下面的链接中

enter image description here 在此处输入图片说明

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.

相关问题 PicklingError:无法腌制 <class 'module'> :内建属性查找模块失败 - PicklingError: Can't pickle <class 'module'>: attribute lookup module on builtins failed Python:多重处理-肥皂水-_pickle.PicklingError:无法腌制 <class> 属性查找失败 - Python: Multiprocessing - Suds - _pickle.PicklingError: Can't pickle <class> attribute lookup failed 错误:_pickle.PicklingError:不能腌制<function <lambda>在 0x0000002F2175B048&gt;:属性查找<lambda>在 __main__ 上失败 - Error :_pickle.PicklingError: Can't pickle <function <lambda> at 0x0000002F2175B048>: attribute lookup <lambda> on __main__ failed pickle.PicklingError: 不能腌制<function past_match_sim at 0x7fa26e03b7b8> : __main__ 上的属性查找 past_match_sim 失败</function> - pickle.PicklingError: Can't pickle <function past_match_sim at 0x7fa26e03b7b8>: attribute lookup past_match_sim on __main__ failed Python:_pickle.PicklingError:无法腌制<function <lambda> ></function> - Python: _pickle.PicklingError: Can't pickle <function <lambda>> pickle.PicklingError: Can't pickle: 它与 object 不同 - pickle.PicklingError: Can't pickle: it's not the same object as 搁置:不能泡菜 <class 'method'> :属性查找builtins.method失败 - Shelve: Can't pickle <class 'method'>: attribute lookup builtins.method failed nltk.tag.hmm上的Python HMM标记器_pickle.PicklingError属性查找估计器失败 - Python HMM tagger _pickle.PicklingError attribute lookup estimator on nltk.tag.hmm failed PicklingError:无法腌制<class 'ctypes.c_char_array_x'> : ctypes 上的属性查找 c_char_Array_X 失败</class> - PicklingError: Can't pickle <class 'ctypes.c_char_Array_X'>: attribute lookup c_char_Array_X on ctypes failed 不能腌制<class> : 导入模块失败</class> - Can't pickle <class>: import of module failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM