<强>报错信息:强>
回溯(最近的电话最后):
_local对象 引用>
文件“D:/flaskProject/测试。py”,第35行,在测试
pool.apply(自我。,arg游戏=(我))
文件”Python37-32 \ lib \多处理\池。py”, 261行,在适用
回归自我。apply_async (kwds func, args) . get ()
文件“\ lib \多处理\池。py”, 657行,在
提高自我。_value
文件”\ Python37-32 \ lib \多处理\池。py”, 431行,在_handle_tasks
put(任务)
文件”\ Python37-32 \ lib \多处理\连接。py”, 206行,在发送
self._send_bytes (_ForkingPickler.dumps (obj)
文件“* \ Python37-32 \ lib \多处理\减少。py”, 51,转储
cls (buf协议).dump (obj)
TypeError:泡菜_thread不能。<强>原类的构造函数:强>
类threadtest: def __init__(自我、ipList、用户、密码): 自我。ipList=ipList 自我。httpAuth=HTTPDigestAuth(用户、密码) 返回 def(自我,i): url=" http://" +我+“/名称”=响应请求。get (url, self.httpAuth) 打印(response.text) 返回 def测试(自我): 池=池(过程=2) 因为我在self.ipList: pool.apply(自我。,arg游戏=(我)) pool.close () pool.join () 返回 >之前如果name==爸饕? ipList=[‘192.168.2.1’,‘192.168.2.2’,‘192.168.2.3’,‘192.168.2.4’,‘192.168.2.5’,)=threadtest (ipList,“管理”、“管理”) “()<强>原因:强>
在类中对属性进行初始化使用了其它类返回的句柄进行初始化导致,HTTPDigestAuth的返回值不能进行序列化,也就是不能作为cls (buf、协议).dump (obj)的参数进行序列化。
将自我。httpAuth=HTTPDigestAuth (httpUser httpPassword)修改为:
自我。httpUser
引用>
自我。httpPassword
并将函数HTTPDigestAuth放到类的方法中
修改后:
类threadtest: def __init__(自我、ipList、用户、密码): 自我。ipList=ipList 自我。用户=用户 自我。密码=密码 返回 def(自我,i): url=" http://" +我+“/名称”=响应请求。get (url, HTTPDigestAuth(自我。用户,self.password)) 打印(response.text) 返回 def测试(自我): 池=池(过程=2) 因为我在self.ipList: pool.apply(自我。,arg游戏=(我)) pool.close () pool.join () 返回 >之前如果name==爸饕? ipList=[‘192.168.2.1’,‘192.168.2.2’,‘192.168.2.3’,‘192.168.2.4’,‘192.168.2.5’,)=threadtest (ipList,“管理”、“管理”) “()以上这篇解决python多线程报错:AttributeError:不能pickle本地对象问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
解决python多线程报错:AttributeError:停下来# 39;t泡菜本地对象问题