title: Django, Boto, S3: Why am I not getting a response suddenly?
body: <p>This has been driving me crazy and I can't figure out where the issue is.  AWS is having issues right now, but this problem was happening before all that and continues to exhibit same behavior.</p>
  
  <p>Summary: I have an admin field that uploads images to S3 and stores the path in the database.  On a fresh apache restart, it works fine for about 20 minutes.  Then it stops working and just hangs on 'waiting for response from <em>domain</em>'  That's it, no error message, just sits there, waiting, and won't work again until I restart apache.  And after restarting apache it works flawlessly until it stops, which happens after 20 minutes best I can tell and is not cause by more or less traffic or a certain number of inserts, deletes, etc.</p>
  
  <p>Here's code for the model:</p>
  
  <pre><code>class SampleImage(models.Model):
      def __unicode__(self):
          return self.name
  
      name = models.CharField(max_length=50)
      front_image = S3EnabledImageField(upload_to='samples')
      back_image = S3EnabledImageField(upload_to='samples')
  </code></pre>
  
  <p>Code for S3EnabledImageField:</p>
  
  <pre><code>class S3EnabledImageField(models.ImageField):
      def generate_filename(self, instance, filename):
          path_join = os.path.join(self.get_directory_name(), self.get_filename(filename))
          return path_join.replace("\\", "/")
  
      def __init__(self, bucket=settings.BUCKET_NAME, verbose_name=None, name=None, width_field=None, height_field=None, **kwargs):
          if settings.USE_AMAZON_S3:
              self.connection = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
              if not self.connection.lookup(bucket):
                  self.connection.create_bucket(bucket)
              self.bucket = self.connection.get_bucket(bucket)
              kwargs['storage'] = S3Storage(self.bucket)
          super(S3EnabledImageField, self).__init__(verbose_name, name, width_field, height_field, **kwargs)
  </code></pre>
  
  <p>Code for S3Storage:</p>
  
  <pre><code>class S3Storage(FileSystemStorage):
      def __init__(self, bucket=None, location=None, base_url=None):
          if location is None:
              location = settings.MEDIA_ROOT
          if base_url is None:
              base_url = settings.MEDIA_URL
          self.location = os.path.abspath(location)
          self.bucket = bucket
          self.base_url = base_url
  
      def _open(self, name, mode='rb'):
          class S3File(File):
              def __init__(self, key):
                  self.key = key
  
              def size(self):
                  return self.key.size
  
              def read(self, *args, **kwargs):
                  return self.key.read(*args, **kwargs)
  
              def write(self, content):
                  self.key.set_contents_from_string(content)
  
              def close(self):
                  self.key.close()
  
          return S3File(Key(self.bucket, name))
  
      def _save(self, name, content):
          key = Key(self.bucket, name)
          if hasattr(content, 'temporary_file_path'):
              key.set_contents_from_filename(content.temporary_file_path())
          elif isinstance(content, File):
              key.set_contents_from_file(content)
          else:
              key.set_contents_from_string(content)
          key.make_public()
  
          return name
  
      def delete(self, name):
          self.bucket.delete_key(name)
  
      def exists(self, name):
          return Key(self.bucket, name).exists()
  
      def listdir(self, path):
          return [key.name for key in self.bucket.list()]
  
      def path(self, name):
          raise NotImplementedError
  
      def size(self, name):
          return self.bucket.get_key(name).size
  
      def url(self, name):
          return Key(self.bucket, name).generate_url(100000)
  
      def get_available_name(self, name):
          return name
  </code></pre>