Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions django_s3_storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,16 @@ def open(self, mode="rb"):
self.file = self._storage.open(self.name, mode).file
return super().open(mode)


class _LocalSession(local):
def __init__(self):
self.session = boto3.session.Session()


local_session = _LocalSession()

class _Local(local):

class _Local(local):
"""
Thread-local connection manager.

Expand All @@ -117,8 +124,7 @@ def __init__(self, storage):
connection_kwargs["aws_session_token"] = storage.settings.AWS_SESSION_TOKEN
if storage.settings.AWS_S3_ENDPOINT_URL:
connection_kwargs["endpoint_url"] = storage.settings.AWS_S3_ENDPOINT_URL
self.session = boto3.session.Session()
self.s3_connection = self.session.client(
self.s3_connection = local_session.session.client(
"s3",
config=Config(
s3={"addressing_style": storage.settings.AWS_S3_ADDRESSING_STYLE},
Expand Down