多处理-ChicklingError:can can can pickle< class' botocore.client.s3'>>>:属性查找botocore.client on botocore.client失败
以下代码获取错误
_pickle.picklingerror:不能泡菜< class'botocore.client.s3'>:botocore on botocore.client.client失败
import boto3
import concurrent.futures as cf
class Boto3:
def __init__(self) -> None:
self.s3client = boto3.client("s3")
class C:
def __init__(self, s3) -> None:
self.s3 = s3 # this instance variable may have caused the problem
def f(self, a):
x = self.s3
return a*a
c = C(Boto3())
p = [1,2,3]
def run(f, p):
executor = cf.ProcessPoolExecutor(max_workers=3)
result = executor.map(f, p)
print([x for x in result])
if __name__ == "__main__":
run(c.f, p)
是解决问题的方法吗?
但是,使用全局变量和函数有效吗?
s3 = boto3.client("s3")
def g(a):
x = s3
....
result = executor.map(g, p)
另外,如果s3client
是类变量,则可以工作。
class Boto3:
s3client = boto3.client("s3")
The following code gets the error of
_pickle.PicklingError: Can't pickle <class 'botocore.client.S3'>: attribute lookup S3 on botocore.client failed
import boto3
import concurrent.futures as cf
class Boto3:
def __init__(self) -> None:
self.s3client = boto3.client("s3")
class C:
def __init__(self, s3) -> None:
self.s3 = s3 # this instance variable may have caused the problem
def f(self, a):
x = self.s3
return a*a
c = C(Boto3())
p = [1,2,3]
def run(f, p):
executor = cf.ProcessPoolExecutor(max_workers=3)
result = executor.map(f, p)
print([x for x in result])
if __name__ == "__main__":
run(c.f, p)
Is it a way to resolve the issue?
However, using global variable and functions works?
s3 = boto3.client("s3")
def g(a):
x = s3
....
result = executor.map(g, p)
Also, it works if s3client
is a class variable.
class Boto3:
s3client = boto3.client("s3")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论