Django stops working with RuntimeError: populate() isn't reentrant Django stops working with RuntimeError: populate() isn't reentrant django django

Django stops working with RuntimeError: populate() isn't reentrant


This is caused by a bug in your Django settings somewhere. Unfortunately, Django's hiding the bug behind this generic and un-useful error message.

To reveal the true problem, open django/apps/registry.py and around line 80, replace:

raise RuntimeError("populate() isn't reentrant")

with:

self.app_configs = {}

This will allow Django to continue loading, and reveal the actual error.

I've encountered this error for several different causes. Once was because I had a bad import in one of my app's admin.py.


My server's administrator restarted Apache, and that magically fixed this problem. The exact same Python files loaded without causing populate() isn't reentrant. I even tried loading another file with a syntax error, then fixing it, and the server was able to load the new file and run correctly with no problems.

I still don't know what was going wrong, but I'm marking this as answered since the problem is gone. (Well, I'll mark it as answered as soon as StackOverflow allows me to accept my own answer.)

Update: After continuing to get this error when I accidentally upload Python with syntax errors, I figured out a workaround that's easier than restarting Apache. When WSGI starts throwing the populate() isn't reentrant error, I replace my Django project's wsgi.py with this simple function:

def application(environ, start_response):    if environ['mod_wsgi.process_group'] != '':         import signal        os.kill(os.getpid(), signal.SIGINT)    return ["killed"]

Then I reload my website, and the WSGI daemon process restarts (which I can tell by looking at the Apache log, even though the website still displays the same 500 error).

If I then change wsgi.py back to normal and reload again, WSGI successfully picks up my code without throwing populate() isn't reentrant (assuming I have no syntax errors this time). So the entirety of Apache doesn't need to restart, just the WSGI process, and I can do that without root privileges.


I know this is an old answer but I will contribute with my solution:

As a way to diagnose the source of the problem run manage.py checkand see if you find anything there

In my case an outdated requirement was the issue and django was failing to import a submodule

Make sure that your requirements are up to date