iT邦幫忙

0

Django+ Celery+ uWSGI 問題

Linux ubuntu
虛擬環境配置:
Django2.0
python 3.6
Celery 4.2.1
使用 redis 作為 broker
在本地運行可以正常使用
使用uWSGI直接開啟也可以正常運行網站

uwsgi --socket mysite.sock --module mysite.wsgi --chmod-socket = 666

但如果使用uWSGI的ini配置就會出現以下錯誤訊息

Traceback (most recent call last):
  File "./mysite/__init__.py", line 5, in <module>
    from .celery import app as celery_app
  File "./mysite/celery.py", line 7, in <module>
    app.config_from_object('django.conf:settings', namespace='CELERY')
TypeError: config_from_object() got an unexpected keyword argument 'namespace'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***

將Celery改為 3.1.8版本
並修改相關文件配置
就可以正常運行uWSGI

但Celery3.1.8在本地運行就是失敗的
導致部署上去也無法使用
Celery3.1.8運行會出現以下問題:

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

嘗試過添加:
import django
django.setup()
會出現以下錯誤訊息

  File "/home/user/env/lib/python3.6/site-packages/celery/fixups/django.py", line 137, in validate_models
    from django.core.management.validation import get_validation_errors

最後覺得在uWSGI的ini配置檔案可能有問題
在此也附上

[uwsgi]

# Django-related settings 
# the base directory (full path) 
chdir            = /home/user/env/mysite
 # Django's wsgi file 
module           = mysite.wsgi
 # the virtualenv (full path) 
home             = /home/user/env

# process-related settings 
# master 
master           =  true 
# maximum number of worker processes 
processes        = 10
 # the socket (use the full path to be safe 
socket           = /home/user/env/mysite/mysite.sock
 # ... with appropriate permissions - may be needed 
chmod-socket = 666 
# clear environment on exit 
vacuum           =  true



froce iT邦大師 1 級 ‧ 2018-09-05 13:58:08 檢舉
你ini有配置 virtualenv,用uwsgi 指令看起來沒吃到 virtualenv 的設定。
先拿掉 home = /home/user/env 看看。
果真如此,太厲害了

尚未有邦友回答

立即登入回答