我正在尝试使用Foreman/Honcho来管理基于Procfile的Django应用程序.当我启动应用程序查看正常的python manage.py runserver时,一切正常.但是,当我通过honcho start或foreman start web启动应用程序时,我收到此错误:
11:59:31 system | web.1 started (pid=27959)
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Starting gunicorn 19.4.5
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Listening at: http://0.0.0.0:5000 (27959)
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27959] [INFO] Using worker: sync
11:59:31 web.1 | [2016-04-26 11:59:31 -0700] [27962] [INFO] Booting worker with pid: 27962
11:59:31 web.1 | [2016-04-26 18:59:31 +0000] [27962] [ERROR] Exception in worker process:
11:59:31 web.1 | Traceback (most recent call last):
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/arbiter.py",line 515,in spawn_worker
11:59:31 web.1 | worker.init_process()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/workers/base.py",line 122,in init_process
11:59:31 web.1 | self.load_wsgi()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/workers/base.py",line 130,in load_wsgi
11:59:31 web.1 | self.wsgi = self.app.wsgi()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/app/base.py",line 67,in wsgi
11:59:31 web.1 | self.callable = self.load()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/app/wsgiapp.py",line 65,in load
11:59:31 web.1 | return self.load_wsgiapp()
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/app/wsgiapp.py",line 52,in load_wsgiapp
11:59:31 web.1 | return util.import_app(self.app_uri)
11:59:31 web.1 | File "/Library/Python/2.7/site-packages/gunicorn/util.py",line 357,in import_app
11:59:31 web.1 | __import__(module)
11:59:31 web.1 | File "../wsgi.py",line 17,in Failed to boot.
11:59:31 system | web.1 stopped (rc=3)
这是尝试安装django-message模块.我和其他模块也有同样的问题.我也遇到了与django-webpack-loader相同的问题.我还应该提到我在virtualenv和停用时都收到了错误.
这是安装django-messages的命令:
$> pip install django-messages
Requirement already satisfied (use --upgrade to upgrade): django-messages in ./lib/python2.7/site-packages
已安装的应用;
INSTALLED_APPS = (
'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','my_app','django_messages',)
我不确定我可以提供哪些其他信息来帮助排除故障,但基本问题是如何安装应用程序以与foreman / honcho一起工作?
不幸的是,您不能只将/ path / to / virtualenv / bin / activate作为Procfile的一部分调用,因为当其中一个子进程退出时,Honcho会退出,如in this Github issue thread所述.但是,您可以执行此脚本和您的python脚本一个子shell使用&&操作符将它们链接在一起:
web: source venv/bin/activate && python manage.py
或者,您可以更好地修改wsgi.py包装器,以便在导入Django应用程序之前显式引入virtualenv的库:
# Activate your virtual env
activate_env=os.path.expanduser("/path/to/virtualenv/bin/activate_this.py")
execfile(activate_env,dict(__file__=activate_env))
这些应该在导入任何模块(os除外)之前执行,以确保您的应用程序读取正确的站点库.
最后,Honcho本身支持在Procfile文件旁边使用.env文件,这些文件设置了运行进程的环境.该文件的格式与任何bash脚本相同.您可以使用.env文件将PYTHONPATH和PYTHONHOME设置为指向Virtualenv中的库,然后在Procfile中指定Virtualenv中的显式Python解释器.
.env文件
PYTHONHOME=/path/to/virtualenv/lib/python2.7
PYTHONHOME=