web-dev-qa-db-ja.com

boto3クライアントはスレッドセーフです

S3のboto3低レベルクライアントはスレッドセーフですか?ドキュメントはそれについて明示的ではありません。

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#client

同様の問題がGithubで説明されています

https://github.com/boto/botocore/issues/1246

しかし、メンテナーからの答えはまだありません。

9
Andrey Novosad

Boto3の Multithreading/Processing ドキュメンテーションを見ると、個々のスレッドによって変更できるインスタンス間で共有データがあるため、セッションごとに1つのクライアントを推奨していることがわかります。

また、この正確な質問に対するgithubの未解決の問題があるようです。 https://github.com/boto/botocore/issues/1246

9
Skam

最近、concurrent.futures.ThreadPoolExecutorを使用して単一のbotoクライアントインスタンスを使用してみました。 botoからの例外に遭遇します。この場合、botoクライアントはスレッドセーフではないと仮定します。

私が得た例外

  File "xxx/python3.7/site-packages/boto3/session.py", line 263, in client
    aws_session_token=aws_session_token, config=config)
  File "xxx/python3.7/site-packages/botocore/session.py", line 827, in create_client
    endpoint_resolver = self._get_internal_component('endpoint_resolver')
  File "xxx/python3.7/site-packages/botocore/session.py", line 694, in _get_internal_component
    return self._internal_components.get_component(name)
  File "xxx/python3.7/site-packages/botocore/session.py", line 906, in get_component
    del self._deferred[name]
1
Pawel