Django populate() isn't reentrant

Solution 1:

This RuntimeError first occured for me after upgrading to Django 1.7 (and still is present with Django 1.8). It is usually caused by an Django application which raises an error, but that error is swallowed somehow.

Here's a workaround which works for me. Add it to your wsgi.py and the real error should be logged:

import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application

try:
    application = get_wsgi_application()
    print 'WSGI without exception'
except Exception:
    print 'handling WSGI exception'
    # Error loading applications
    if 'mod_wsgi' in sys.modules:
        traceback.print_exc()
        os.kill(os.getpid(), signal.SIGINT)
        time.sleep(2.5)

See this thread on modwsgi for more details.

Solution 2:

In the end the problem that I had was that I tried to run a second Django app and did not have the following defined in my apache config:

WSGIDaemonProcess ...
WSGIProcessGroup ...

Just learned that you can run a single django app without defining them but when its two it produces a conflict.

Solution 3:

There will be many reason to causes to populate() isn't reentrant error. If you look at the registry.py in your in django application probably inside this directory
/python2.7/site-packages/django/apps

        # app_config should be pristine, otherwise the code below won't
        # guarantee that the order matches the order in INSTALLED_APPS.
        if self.app_configs:
            raise RuntimeError("populate() isn't reentrant")

As you see in the comment it says app_config should be pristine. Which means if one of configuration is not correct or required library missing it will rise this populate error. I got this error because I have missed sqlite installation. Even as you see there is no mentioning possible causes in the exception. I installed sqlite by this command on debian

pip install pysqlite

It solved my problem. My exception because of missing pysqlite.Your maybe having missing of another required packages or errors in your settings.py

Solution 4:

For those using AWS Lambda (and optionally using zappa) this can happen when the size of code & dependencies zipped into a deployment package exceeds 250MB after decompression.

Typically the zip may only be 50 MB but may decompress to over 250MB so you may need to manually unzip the deployment package to check it isn't too large when uncompressed.

https://docs.aws.amazon.com/lambda/latest/dg/limits.html

Solution 5:

Full disclosure - "populate() isn't reentrant" errors can have multiple causes, and checking any recent config or program changes is a very good idea.

However, this error can also occur when Apache is updated, and a module is no longer valid/is corrupted/needs refreshing. This occurred to us on Webfaction after an Apache update (but may happen on any host).

Using the Apache restart script will NOT help this, because the modules remain loaded on the restart. Depending on your system, and whether the mods are cached even when Apache is shut down, this may help.

Fully stop Apache. On Webfaction, that is:

~/webapps/<YOUR WEB APP>/apache2/bin/stop

Wait a few seconds, and then...

~/webapps/<YOUR WEB APP>/apache2/bin/start

That should correct the issue. If your system caches the mods, you may have to flush the cache before starting.

Hope this helps!

Here is the link they gave me (I know the error is different, but we had this happen for the same reason with the populate error as well):

https://statusblog.webfaction.com/2018/05/16/regarding-glibc_private-errors-in-your-python-application/