Django app throws spurious exception when importing views from third-party app
Question: I'm working on a Django app that occasionally throws a `ViewDoesNotExist`
exception when trying to import modules from a third-party app (Solango, to be
specific). By "occasionally", I mean often enough to be annoying, but
definitely a minority of requests. Solango is on the app's `PYTHONPATH` and
can be imported reliably through the console. The error also never happens
during local development, so maybe it has something to do with the server
setup (the app uses Apache + mod_wsgi in daemon mode).

Here's a stack trace showing the error occurring in the admin (although it
occurs on pretty much every page on the site):

    
    
    Traceback:
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
      92.                 response = callback(request, *callback_args, **callback_kwargs)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
      445.             return self.index(request)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
      44.         response = view_func(request, *args, **kwargs)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in index
      342.             context_instance=template.RequestContext(request)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/shortcuts/__init__.py" in render_to_response
      20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
      108.     return t.render(context_instance)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      178.         return self.nodelist.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      778.                 bits.append(self.render_node(node, context))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
      791.         return node.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
      97.         return compiled_parent.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      178.         return self.nodelist.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      778.                 bits.append(self.render_node(node, context))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
      791.         return node.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
      97.         return compiled_parent.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      178.         return self.nodelist.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      778.                 bits.append(self.render_node(node, context))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
      791.         return node.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
      245.                     return self.nodelist_true.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      778.                 bits.append(self.render_node(node, context))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
      791.         return node.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
      255.             return self.nodelist_true.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      778.                 bits.append(self.render_node(node, context))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
      791.         return node.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
      24.         result = self.nodelist.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
      778.                 bits.append(self.render_node(node, context))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
      791.         return node.render(context)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
      372.             url = reverse(self.view_name, args=args, kwargs=kwargs)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
      265.             *args, **kwargs)))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
      238.         possibilities = self.reverse_dict.getlist(lookup_view)
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
      165.                     for name in pattern.reverse_dict:
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
      173.                     lookups.appendlist(pattern.callback, (bits, p_pattern))
    File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_callback
      134.             raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))
    
    Exception Type: ViewDoesNotExist at /admin/
    Exception Value: Could not import solango.views. Error was: cannot import name settings
    

Any ideas on what's causing the problem, or at least how I can go about
debugging it?


Answer: Your web server is out of file descriptors. Reconfigure mod_wsgi for daemon
mode.

