From ab70ac41442512620f2d8b28892a37b2e367c0eb Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Sun, 6 Mar 2011 12:23:22 +0000 Subject: [PATCH] Removed lock around SES connection --- django_ses/__init__.py | 55 ++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/django_ses/__init__.py b/django_ses/__init__.py index 306fa142..f7913d80 100644 --- a/django_ses/__init__.py +++ b/django_ses/__init__.py @@ -24,7 +24,6 @@ def __init__(self, fail_silently=False, *args, **kwargs): SESConnection.DefaultHost) self.connection = None - self._lock = threading.RLock() def open(self): """Create a connection to the AWS API server. This can be reused for @@ -60,33 +59,31 @@ def send_messages(self, email_messages): if not email_messages: return - self._lock.acquire() - try: - new_conn_created = self.open() - if not self.connection: - # Failed silently - return - - num_sent = 0 - for message in email_messages: - try: - response = self.connection.send_raw_email( - source=message.from_email, - destinations=message.recipients(), - raw_message=message.message().as_string(), - ) - send_result = response['SendRawEmailResponse']['SendRawEmailResult'] - message.extra_headers['Message-Id'] = send_result['MessageId'] - num_sent += 1 - except SESConnection.ResponseError: - if not self.fail_silently: - raise - pass - - if new_conn_created: - self.close() - - finally: - self._lock.release() + new_conn_created = self.open() + if not self.connection: + # Failed silently + return + + num_sent = 0 + for message in email_messages: + try: + response = self.connection.send_raw_email( + source=message.from_email, + destinations=message.recipients(), + raw_message=message.message().as_string(), + ) + send_response = response['SendRawEmailResponse'] + send_result = send_response['SendRawEmailResult'] + message.extra_headers['Message-Id'] = send_result['MessageId'] + + num_sent += 1 + except SESConnection.ResponseError: + if not self.fail_silently: + raise + pass + + if new_conn_created: + self.close() + return num_sent