Saya telah mengembangkan aplikasi web Django yang disebarkan pada server Apache dengan WSGI, dan semuanya berjalan lancar. Hari ini, saya membuat beberapa perubahan kecil pada aplikasi saya admin.py
dalam upaya untuk menyesuaikan antarmuka Admin Django bawaan, dan awalnya membuat kesalahan sintaks (tanda kurung tidak tertutup). Ini berarti bahwa ketika saya menyentuh wsgi.py
dan memuat kode (saya menjalankan WSGI dalam mode daemon di host virtual saya), situs web saya diganti dengan Kesalahan Server Internal karena WSGI berhenti ketika terjadi kesalahan sintaksis.
Jadi saya memperbaiki kesalahan sintaks, memeriksa bahwa saya tidak memilikinya lagi manage.py check
, dan menyentuh wsgi.py
untuk menerapkan ulang. Tetapi situs web saya masih menampilkan Kesalahan Server Internal! Memeriksa log Apache, inilah yang saya lihat:
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Create interpreter 'quotes.cs.cornell.edu|'.
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Adding '/extra/www/html/quotes/quotes_django' to path.
[Sun Nov 23 13:52:46 2014] [info] mod_wsgi (pid=19093): Adding '/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/' to path.
[Sun Nov 23 13:52:46 2014] [info] [client 128.84.33.19] mod_wsgi (pid=19093, process='quotes.cs.cornell.edu',
application='quotes.cs.cornell.edu|'): Loading WSGI script '/extra/www/html/quotes/quotes_django/quotes_django/
wsgi.py'.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Target WSGI script '/extra/www/html/
quotes/quotes_django/quotes_django/wsgi.py' cannot be loaded as Python module.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Exception occurred processing WSGI
script '/extra/www/html/quotes/quotes_django/quotes_django/wsgi.py'.
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] Traceback (most recent call last):
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/extra/www/html/quotes/quotes_django/
quotes_django/wsgi.py", line 14, in <module>
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] application = get_wsgi_application()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] django.setup()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/__init__.py", line 21, in setup
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] apps.populate(settings.INSTALLED_APPS)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/apps/registry.py", line 115, in populate
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] app_config.ready()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/contrib/admin/apps.py", line 22, in ready
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] self.module.autodiscover()
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/contrib/admin/__init__.py", line 23, in autodiscover
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] autodiscover_modules('admin', register_to=site)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/utils/module_loading.py", line 74, in autodiscover_modules
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] import_module('%s.%s' % (app_config.name,
module_to_search))
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/usr/lib64/python2.7/importlib/__init__.py", line
37, in import_module
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] __import__(name)
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] File "/extra/www/html/quotes/quotes_django/quotespage/
admin.py", line 25
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] approve_quotes.short_description = "Approve selected
quotes"
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] ^
[Sun Nov 23 13:52:46 2014] [error] [client 128.84.33.19] SyntaxError: invalid syntax
[Sun Nov 23 13:53:36 2014] [info] [client 128.84.33.19] mod_wsgi (pid=19093, process='quotes.cs.cornell.edu',
application='quotes.cs.cornell.edu|'): Loading WSGI script '/extra/www/html/quotes/quotes_django/quotes_django/
wsgi.py'.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Target WSGI script '/extra/www/html/
quotes/quotes_django/quotes_django/wsgi.py' cannot be loaded as Python module.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] mod_wsgi (pid=19093): Exception occurred processing WSGI
script '/extra/www/html/quotes/quotes_django/quotes_django/wsgi.py'.
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] Traceback (most recent call last):
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/extra/www/html/quotes/quotes_django/
quotes_django/wsgi.py", line 14, in <module>
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] application = get_wsgi_application()
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] django.setup()
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/__init__.py", line 21, in setup
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] apps.populate(settings.INSTALLED_APPS)
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] File "/opt/rh/python27/root/usr/lib64/python2.7/site-
packages/django/apps/registry.py", line 78, in populate
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] raise RuntimeError("populate() isn't reentrant")
[Sun Nov 23 13:53:36 2014] [error] [client 128.84.33.19] RuntimeError: populate() isn't reentrant
Rangkaian kesalahan pertama menunjukkan WSGI gagal karena kesalahan sintaks di my admin.py
. Namun demikian, rangkaian kesalahan kedua tampaknya memperlihatkan kesalahan internal ke Django:
RuntimeError: populate() isn't reentrant
terlempar dari populate
metode registry.py
.
Googling pesan kesalahan ini mengembalikan sangat sedikit informasi, tidak satupun darinya dari dokumentasi Django. Rupanya, hal itu terkadang bisa terjadi jika Anda menamai aplikasi dua kali di aplikasi Anda settings.py
, tetapi saya tidak melakukannya. Lebih penting lagi, saya belum berubah settings.py
sejak titik di mana situs web berfungsi dengan baik - satu-satunya hal yang saya ubah adalah admin.py
.
Saya mencoba mengembalikan semua perubahan yang saya buat, jadi semua kode Python saya kembali ke keadaan semula ketika situs web berfungsi - dan saya masih mendapatkan populate() isn't reentrant
kesalahan ketika saya mencoba membuat WSGI memuat ulang kode!
Saya juga mencoba mengomentari aplikasi yang berbeda di bagian INSTALLED_APPS settings.py
, dan bahkan dengan hanya 'django.contrib.staticfiles' yang diaktifkan, kesalahan masih terjadi. Anehnya, saya masih mendapatkan kesalahan meskipun saya mengomentari semua aplikasi - Django melempar kesalahan bahkan ketika tidak memuat aplikasi apapun!
Apakah ada yang tahu apa yang terjadi di sini? Atau ada cara yang lebih baik bagi saya untuk men-debug kesalahan ini, karena penelusuran kembali di log Apache cukup tidak membantu?
Catatan: Saya menggunakan Django 1.7, Apache 2.2, dan Python 2.7.
wsgi.py
menghasilkan kesalahan Apache yang sama, dan file .pyc tidak dibuat ulang.