I wanna uploading lots of files to s3 service every time.
I made 10 workers to upload files using thread.
But a message, "Resetting dropped connection", is shown repeatedly.
I guess s3 connection is newly opened per one time.
How can I set connection to keep alive?
import threading
import boto3
s3 = boto3.resource('s3')
class Worker(threading.Thread):
...
def run(self):
s3.Object(bucket, key).put(Body=body)
I suggest that you move the boto3.resource('s3') into the thread. I believe the general advice is to have one resource per thread as they're not thread-safe.
I moved boto3.resource('s3') into each thread, but the same message is shown.
The session itself isn't thread safe, you'll need to create a new one for each thread:
import threading
from boto3.session import Session
class Worker(threading.Thread):
...
def run(self):
s = Session()
s3 = s.resource('s3')
I created new session in each thread.
But Resetting dropped connection message still is shown.
I guess S3 doesn't support Keep-Alive or I quickly send request to server repeatedly.
Thank you for your help.
What's the difference between
s = Session()
s3 = s.resource('s3')
and
s3 = boto3.resource('s3') ?
Most helpful comment
The session itself isn't thread safe, you'll need to create a new one for each thread: