title: Code change monitoring malfunctioning with Django 1.7 on mod-wsgi
body: <p>This is an issue that I've encountered on all my sites that are running Django 1.7 in mod_wsgi.  The nub of the issue is that if, while developing locally, I introduce a fatal error into the codebase, and then subsequently correct it, the code monitoring script doesn't detect the correction.</p>
  
  <p>I use <a href="http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html" rel="nofollow">Graham Dumpleton's monitor.py script</a> to detect changes to the codebase when I'm developing locally (I use apache rather than the Django development server).</p>
  
  <p>It always used to work in Django &lt;= 1.6, but in Django 1.7 I get the following error:</p>
  
  <pre><code>File "/home/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
      django.setup()
  File "/home/me/virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
      apps.populate(settings.INSTALLED_APPS)
  File "/home/me/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
      raise RuntimeError("populate() isn't reentrant")
  RuntimeError: populate() isn't reentrant
  </code></pre>
  
  <p>The irritating thing is that if I correct the error, monitor.py doesn't detect the change, so I have to either restart apache, or touch another file that was already loaded (e.g. the settings file).</p>
  
  <p>I think this is because of the fact that "the reloading code only monitors imported files (aka sys.modules)" (<a href="https://code.djangoproject.com/ticket/22729#comment:3" rel="nofollow">source</a>).  So because the incorrect file wasn't successfully imported, monitor.py doesn't know to restart the process.</p>