2

Im deploying a django application on a intranet environment. I've already set up a testing server and everything is fine (after breaking my head fixing errors).

This time, im seting up the production server and after configuring everything, i got an error 500, here is the httpd/logs/error_log:

traceback

[Thu Oct 27 09:44:15.480662 2016] [:error] [pid 15250] [remote 10.105.40.106:200] mod_wsgi (pid=15250): Target WSGI script '/home/rortega/smce/smce/wsgi.py' cannot be loaded as Python module.
[Thu Oct 27 09:44:15.480706 2016] [:error] [pid 15250] [remote 10.105.40.106:200] mod_wsgi (pid=15250): Exception occurred processing WSGI script '/home/rortega/smce/smce/wsgi.py'.
[Thu Oct 27 09:44:15.480736 2016] [:error] [pid 15250] [remote 10.105.40.106:200] Traceback (most recent call last):
[Thu Oct 27 09:44:15.480764 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce/smce/wsgi.py", line 16, in <module>
[Thu Oct 27 09:44:15.480805 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     application = get_wsgi_application()
[Thu Oct 27 09:44:15.480823 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Oct 27 09:44:15.480852 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     django.setup()
[Thu Oct 27 09:44:15.480868 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
[Thu Oct 27 09:44:15.480892 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     apps.populate(settings.INSTALLED_APPS)
[Thu Oct 27 09:44:15.480908 2016] [:error] [pid 15250] [remote 10.105.40.106:200]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Thu Oct 27 09:44:15.480932 2016] [:error] [pid 15250] [remote 10.105.40.106:200]     raise RuntimeError("populate() isn't reentrant")
[Thu Oct 27 09:44:15.480958 2016] [:error] [pid 15250] [remote 10.105.40.106:200] RuntimeError: populate() isn't reentrant
[Thu Oct 27 09:44:15.561544 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] mod_wsgi (pid=15250): Target WSGI script '/home/rortega/smce/smce/wsgi.py' cannot be loaded as Python module.
[Thu Oct 27 09:44:15.561571 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] mod_wsgi (pid=15250): Exception occurred processing WSGI script '/home/rortega/smce/smce/wsgi.py'.
[Thu Oct 27 09:44:15.561597 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] Traceback (most recent call last):
[Thu Oct 27 09:44:15.561623 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce/smce/wsgi.py", line 16, in <module>
[Thu Oct 27 09:44:15.561658 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     application = get_wsgi_application()
[Thu Oct 27 09:44:15.561675 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Thu Oct 27 09:44:15.561703 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     django.setup()
[Thu Oct 27 09:44:15.561719 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
[Thu Oct 27 09:44:15.561743 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     apps.populate(settings.INSTALLED_APPS)
[Thu Oct 27 09:44:15.561774 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]   File "/home/rortega/smce_env/lib/python3.5/site-packages/django/apps/registry.py", line 78, in populate
[Thu Oct 27 09:44:15.561800 2016] [:error] [pid 15250] [remote 10.105.40.106:54216]     raise RuntimeError("populate() isn't reentrant")
[Thu Oct 27 09:44:15.561824 2016] [:error] [pid 15250] [remote 10.105.40.106:54216] RuntimeError: populate() isn't reentrant


Another things i noticed before cheking funtionality:

  • When executing makemigrations, only one model file of my 4 apps made the migrations, like if there is only one app
  • python manage.py runserver without errors
Rafael Ortega
  • 434
  • 5
  • 15
  • In general, when you see this error you need to go back in the log and find the first error message related to the WSGI script not being able to be loaded. That will give you the real reason for the problem. The subsequent messages will be different because of a change in Django a few versions back which means that you can't attempt to initialise Django more than once in the process. – Graham Dumpleton Oct 27 '16 at 19:41

2 Answers2

2

RuntimeError: populate() isn't reentrant

In my experience this usually means there is an error in the Django project somewhere. It can be hard to locate. Also, don't forget to restart apache.

When executing makemigrations, only one model file of my 4 apps made the migrations, like if there is only one app

Try pointing makemigrations to the specific app:

python manage.py makemigrations appname

Don't forget to apply migrations afterward:

python manage.py migrate
called2voyage
  • 252
  • 9
  • 28
  • Ok, ill make the migrations per app. also ill check everithing in my django app. Thanx! ill let you know the results – Rafael Ortega Oct 27 '16 at 16:10
  • @Izuzvo Any luck? – called2voyage Oct 27 '16 at 18:31
  • It seems to be something with the mod_wsgi runing under the python2.7. so i recompiled it with tha thag `--with-python=/usr/local/bin/python3.5` following [this solution](http://stackoverflow.com/questions/38256266/how-to-compile-mod-wsgi-4-5-3-with-python3-5-2-under-centos7-apache-2-4-6). But it told me this `error: Failed to locate the Python library /usr/local/lib/libpython3.3m.so`. later i tried to rebuild python3 with --enable-shared but i got [this](http://unix.stackexchange.com/questions/319388/centos-7-python3-error-while-loading-shared-libraries-libpython3-5m-so-1-0) – Rafael Ortega Oct 27 '16 at 18:37
  • @Izuzvo I've been in that exact position. Not sure if the same cause though. In my case it was a server configuration issue. – called2voyage Oct 27 '16 at 18:39
  • @Izuzvo Are you building python3 as root? – called2voyage Oct 27 '16 at 18:40
  • my my... i was running everything as a user with sudo privileges... ill do everything again as root – Rafael Ortega Oct 27 '16 at 18:47
  • @Izuzvo I don't know if that will fix your problem. I was just curious. I would think sudo would be sufficient. – called2voyage Oct 27 '16 at 18:53
  • @Izuzvo Now that you got your other issue fixed, is the populate error still appearing? Also, did you get the other app to make migrations? – called2voyage Oct 28 '16 at 13:33
  • Not anymore, everything works fine now, i'll write an answer with the steps i did to fix it. Also thanx for you help! – Rafael Ortega Oct 28 '16 at 14:04
0

For everyone getting this problem, it can be anything, like a wrong django configuration or something with de mod_wsgi. in my case it was that i needed to build python 3 with the --enable-shared tag.

if this is also your case, you can follow this.

Community
  • 1
  • 1
Rafael Ortega
  • 434
  • 5
  • 15
  • Can also be caused by a database not being available at the time that the processes start. For such transient issues where it could recover, more recent mod_wsgi versions have a ``startup-timeout`` option which can be set for ``WSGIDaemonProcess``. With this set, if the WSGI script file cannot be loaded, after multiple possible attempts, within the startup timeout period, the process will be restarted. That way if transient problem and gets stuck with the reentrant initialisation problem, process will be kicked out and may work next time. – Graham Dumpleton Oct 28 '16 at 20:02