Has a strange problem with MemoryError in my Django project.
- Ubuntu 11
- Apache2
- Nginx
- mod_wsgi
- python2.7
I have a template tag that resizes images using PIL and works fine on my dev machine, but during production it causes a 500 error with large images (~ 800 pixels). The template tag seems to work without problems, but only if the original image is already very small. The template tag is a modified version of http://djangosnippets.org/snippets/1944/
Just tried recompiling mod_wsgi for python2.7 - same error.
Is there a way to allocate more memory, or maybe something else that I just don't understand?
Any help would be greatly appreciated!
Traceback emailed me:
Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/var/www/rizzyhome.com/www/django/rizzyhome/products/views.py", line 31, in designs context_instance=RequestContext(request) File "/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py", line 20, in render_to_response return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 188, in render_to_string return t.render(context_instance) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 123, in render return self._render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 117, in _render return self.nodelist.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 757, in render_node return node.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 127, in render return compiled_parent._render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 117, in _render return self.nodelist.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 757, in render_node return node.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 127, in render return compiled_parent._render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 117, in _render return self.nodelist.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 757, in render_node return node.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 64, in render result = block.nodelist.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 757, in render_node return node.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py", line 64, in render result = block.nodelist.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 757, in render_node return node.render(context) File "/usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py", line 227, in render nodelist.append(node.render(context)) File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 885, in render return func(*func_args) File "/var/www/rizzyhome.com/www/django/rizzyhome/products/templatetags/yair.py", line 108, in thumbnail import Image, ImageOps File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 45, in <module> __import__("FixTk") File "/usr/lib/python2.7/lib-tk/FixTk.py", line 15, in <module> import ctypes File "/usr/lib/python2.7/ctypes/__init__.py", line 549, in <module> CFUNCTYPE(c_int)(lambda: None) MemoryError
Edit: add code
import os, errno from django import template from django.conf import settings register = template.Library() def _mkdir_p(path): try: os.makedirs(path) except OSError as exc: