From b0c94ff56e3f7cc4d378992abe337d3fa52d9e9e Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Thu, 6 Jun 2019 09:57:49 +0100 Subject: [PATCH] Use boto3 session from localdata. This prevents issues when the thread-unsafe Session() is used by multiple threads by allocating one in local_data. --- s3_storage_provider.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/s3_storage_provider.py b/s3_storage_provider.py index 28cfe2d..5dedc53 100644 --- a/s3_storage_provider.py +++ b/s3_storage_provider.py @@ -141,7 +141,10 @@ class _S3DownloadThread(threading.Thread): self.deferred = deferred def run(self): - session = boto3.session.Session() + local_data = threading.local() + if not hasattr(local_data, "b3_session"): + local_data.b3_session = boto3.session.Session() + session = local_data.b3_session s3 = session.client('s3', **self.api_kwargs) try: