Skip to content

Commit ccc4c85

Browse files
authored
Merge pull request #136 from Uxio0/master
Add AWS_S3_USE_THREADS
2 parents 6e1b4b2 + 19685f9 commit ccc4c85

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.rst

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
django-s3-storage changelog
22
===========================
33

4+
0.13.6
5+
------
6+
- Adding `AWS_S3_USE_THREADS` to fix `gevent` issues (@uxio0).
7+
48
0.13.5
59
------
610

README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ Use the following settings to configure the S3 file storage. You must provide at
116116
# extra characters appended.
117117
AWS_S3_FILE_OVERWRITE = False
118118
119+
# If True, use default behaviour for boto3 of using threads when doing S3 operations. If gevent or similar
120+
# is used it must be disabled
121+
AWS_S3_USE_THREADS = True
122+
119123
**Important:** Several of these settings (noted above) will not affect existing files. To sync the new settings to
120124
existing files, run ``./manage.py s3_sync_meta django.core.files.storage.default_storage``.
121125

django_s3_storage/storage.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import boto3
1717
from botocore.client import Config
18+
from boto3.s3.transfer import TransferConfig
1819
from botocore.exceptions import ClientError
1920
from django.conf import settings
2021
from django.contrib.staticfiles.storage import ManifestFilesMixin
@@ -149,7 +150,8 @@ class S3Storage(Storage):
149150
"AWS_S3_KMS_ENCRYPTION_KEY_ID": "",
150151
"AWS_S3_GZIP": True,
151152
"AWS_S3_SIGNATURE_VERSION": "s3v4",
152-
"AWS_S3_FILE_OVERWRITE": False
153+
"AWS_S3_FILE_OVERWRITE": False,
154+
"AWS_S3_USE_THREADS": True,
153155
}
154156

155157
s3_settings_suffix = ""
@@ -188,6 +190,8 @@ def _setup(self):
188190
)
189191
# Create a thread-local connection manager.
190192
self._connections = _Local(self)
193+
# Set transfer config for S3 operations
194+
self._transfer_config = TransferConfig(use_threads=self.settings.AWS_S3_USE_THREADS)
191195

192196
@property
193197
def s3_connection(self):
@@ -326,7 +330,7 @@ def _save(self, name, content):
326330
content.seek(0)
327331
# Save the file.
328332
self.s3_connection.upload_fileobj(content, put_params.pop('Bucket'), put_params.pop('Key'),
329-
ExtraArgs=put_params)
333+
ExtraArgs=put_params, Config=self._transfer_config)
330334
# Close all temp files.
331335
for temp_file in temp_files:
332336
temp_file.close()

0 commit comments

Comments
 (0)