简体   繁体   English

将python应用部署到heroku,苦苦挣扎于gunicorn配置

[英]Deploying a python app to heroku, struggling with gunicorn configuration

I've inherited a python django app and am trying to breathe new life in it.我继承了一个 python django 应用程序,并试图为它注入新的活力。 It's currently using python 2.7 and many old packages that I will eventually need to upgrade.它目前正在使用 python 2.7 和许多我最终需要升级的旧包。 But the first thing before upgrading is I want to have it running successfully on heroku.但是升级之前的第一件事是我想让它在heroku上成功运行。 So far I have it running fine locally, but I'm running into issues with heroku and gunicorn.到目前为止,我在本地运行良好,但我遇到了 heroku 和 gunicorn 的问题。

Here is the error I'm getting:这是我得到的错误:

2020-09-10T03:48:27.212247+00:00 heroku[web.1]: Starting process with command `gunicorn spotlit_due_diligence.spotlit_due_diligence.wsgi:application`
2020-09-10T03:48:29.477479+00:00 heroku[web.1]: State changed from starting to up
2020-09-10T03:48:29.206728+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [4] [INFO] Starting gunicorn 19.10.0
2020-09-10T03:48:29.207159+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [4] [INFO] Listening at: http://0.0.0.0:45741 (4)
2020-09-10T03:48:29.207253+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [4] [INFO] Using worker: sync
2020-09-10T03:48:29.211268+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [11] [INFO] Booting worker with pid: 11
2020-09-10T03:48:29.250434+00:00 app[web.1]: [2020-09-10 03:48:29 +0000] [13] [INFO] Booting worker with pid: 13
2020-09-10T03:48:29.000000+00:00 app[api]: Build succeeded
2020-09-10T03:48:30.075238+00:00 app[web.1]: [2020-09-10 03:48:30 +0000] [11] [ERROR] Exception in worker process
2020-09-10T03:48:30.075250+00:00 app[web.1]: Traceback (most recent call last):
2020-09-10T03:48:30.075251+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 586, in spawn_worker
2020-09-10T03:48:30.075251+00:00 app[web.1]: worker.init_process()
2020-09-10T03:48:30.075251+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in init_process
2020-09-10T03:48:30.075252+00:00 app[web.1]: self.load_wsgi()
2020-09-10T03:48:30.075252+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-09-10T03:48:30.075252+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-09-10T03:48:30.075253+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-09-10T03:48:30.075253+00:00 app[web.1]: self.callable = self.load()
2020-09-10T03:48:30.075254+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2020-09-10T03:48:30.075254+00:00 app[web.1]: return self.load_wsgiapp()
2020-09-10T03:48:30.075254+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2020-09-10T03:48:30.075255+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-09-10T03:48:30.075255+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 350, in import_app
2020-09-10T03:48:30.075255+00:00 app[web.1]: __import__(module)
2020-09-10T03:48:30.075255+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/wsgi.py", line 33, in <module>
2020-09-10T03:48:30.075256+00:00 app[web.1]: application = get_wsgi_application()
2020-09-10T03:48:30.075256+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
2020-09-10T03:48:30.075256+00:00 app[web.1]: django.setup()
2020-09-10T03:48:30.075256+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
2020-09-10T03:48:30.075256+00:00 app[web.1]: configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
2020-09-10T03:48:30.075257+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
2020-09-10T03:48:30.075257+00:00 app[web.1]: self._setup(name)
2020-09-10T03:48:30.075257+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
2020-09-10T03:48:30.075257+00:00 app[web.1]: self._wrapped = Settings(settings_module)
2020-09-10T03:48:30.075257+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
2020-09-10T03:48:30.075258+00:00 app[web.1]: mod = importlib.import_module(self.SETTINGS_MODULE)
2020-09-10T03:48:30.075258+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
2020-09-10T03:48:30.075258+00:00 app[web.1]: __import__(name)
2020-09-10T03:48:30.075258+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/settings/powell.py", line 93, in <module>
2020-09-10T03:48:30.075259+00:00 app[web.1]: os.mkdir('encryption_keys')
2020-09-10T03:48:30.075259+00:00 app[web.1]: OSError: [Errno 17] File exists: 'encryption_keys'
2020-09-10T03:48:30.075406+00:00 app[web.1]: [2020-09-10 03:48:30 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-09-10T03:48:30.455830+00:00 app[web.1]: In file included from /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/syslimits.h:7:0,
2020-09-10T03:48:30.455837+00:00 app[web.1]: from /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:34,
2020-09-10T03:48:30.455838+00:00 app[web.1]: from /app/.heroku/python/include/python2.7/Python.h:19,
2020-09-10T03:48:30.455839+00:00 app[web.1]: from .heroku/python/lib/python2.7/site-packages/magic/__pycache__/_cffi__x14a33f6ax54cebdac.c:2:
2020-09-10T03:48:30.455839+00:00 app[web.1]: /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed/limits.h:194:15: fatal error: limits.h: No such file or directory
2020-09-10T03:48:30.455840+00:00 app[web.1]: #include_next <limits.h>  /* recurse down to the real one */
2020-09-10T03:48:30.455841+00:00 app[web.1]: ^~~~~~~~~~
2020-09-10T03:48:30.455847+00:00 app[web.1]: compilation terminated.
2020-09-10T03:48:30.460417+00:00 app[web.1]: [2020-09-09 22:48:30 +0000] [13] [ERROR] Exception in worker process
2020-09-10T03:48:30.460418+00:00 app[web.1]: Traceback (most recent call last):
2020-09-10T03:48:30.460419+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 586, in spawn_worker
2020-09-10T03:48:30.460420+00:00 app[web.1]: worker.init_process()
2020-09-10T03:48:30.460420+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in init_process
2020-09-10T03:48:30.460420+00:00 app[web.1]: self.load_wsgi()
2020-09-10T03:48:30.460421+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-09-10T03:48:30.460421+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-09-10T03:48:30.460421+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-09-10T03:48:30.460422+00:00 app[web.1]: self.callable = self.load()
2020-09-10T03:48:30.460437+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2020-09-10T03:48:30.460437+00:00 app[web.1]: return self.load_wsgiapp()
2020-09-10T03:48:30.460438+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2020-09-10T03:48:30.460438+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-09-10T03:48:30.460438+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 350, in import_app
2020-09-10T03:48:30.460439+00:00 app[web.1]: __import__(module)
2020-09-10T03:48:30.460440+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/wsgi.py", line 33, in <module>
2020-09-10T03:48:30.460440+00:00 app[web.1]: application = get_wsgi_application()
2020-09-10T03:48:30.460440+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
2020-09-10T03:48:30.460441+00:00 app[web.1]: django.setup()
2020-09-10T03:48:30.460441+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
2020-09-10T03:48:30.460441+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2020-09-10T03:48:30.460442+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
2020-09-10T03:48:30.460442+00:00 app[web.1]: app_config = AppConfig.create(entry)
2020-09-10T03:48:30.460442+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
2020-09-10T03:48:30.460443+00:00 app[web.1]: module = import_module(entry)
2020-09-10T03:48:30.460444+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
2020-09-10T03:48:30.460444+00:00 app[web.1]: __import__(name)
2020-09-10T03:48:30.460444+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/magic/__init__.py", line 1, in <module>
2020-09-10T03:48:30.460445+00:00 app[web.1]: from . import ffi
2020-09-10T03:48:30.460445+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/magic/ffi.py", line 27, in <module>
2020-09-10T03:48:30.460446+00:00 app[web.1]: ext_package="magic")
2020-09-10T03:48:30.460446+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/api.py", line 437, in verify
2020-09-10T03:48:30.460447+00:00 app[web.1]: lib = self.verifier.load_library()
2020-09-10T03:48:30.460447+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/verifier.py", line 113, in load_library
2020-09-10T03:48:30.460447+00:00 app[web.1]: self._compile_module()
2020-09-10T03:48:30.460448+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/verifier.py", line 210, in _compile_module
2020-09-10T03:48:30.460448+00:00 app[web.1]: outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
2020-09-10T03:48:30.460448+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/ffiplatform.py", line 29, in compile
2020-09-10T03:48:30.460449+00:00 app[web.1]: outputfilename = _build(tmpdir, ext, compiler_verbose)
2020-09-10T03:48:30.460449+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/cffi/ffiplatform.py", line 62, in _build
2020-09-10T03:48:30.460450+00:00 app[web.1]: raise VerificationError('%s: %s' % (e.__class__.__name__, e))
2020-09-10T03:48:30.460450+00:00 app[web.1]: VerificationError: CompileError: command 'gcc' failed with exit status 1
2020-09-10T03:48:30.460742+00:00 app[web.1]: [2020-09-09 22:48:30 +0000] [13] [INFO] Worker exiting (pid: 13)
2020-09-10T03:48:30.512245+00:00 app[web.1]: Traceback (most recent call last):
2020-09-10T03:48:30.512247+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2020-09-10T03:48:30.512302+00:00 app[web.1]: sys.exit(run())
2020-09-10T03:48:30.512325+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 61, in run
2020-09-10T03:48:30.512364+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-09-10T03:48:30.512385+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 223, in run
2020-09-10T03:48:30.512517+00:00 app[web.1]: super(Application, self).run()
2020-09-10T03:48:30.512521+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
2020-09-10T03:48:30.512562+00:00 app[web.1]: Arbiter(self).run()
2020-09-10T03:48:30.512565+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 232, in run
2020-09-10T03:48:30.512633+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2020-09-10T03:48:30.512637+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 345, in halt
2020-09-10T03:48:30.512724+00:00 app[web.1]: self.stop()
2020-09-10T03:48:30.512724+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 396, in stop
2020-09-10T03:48:30.512823+00:00 app[web.1]: time.sleep(0.1)
2020-09-10T03:48:30.512824+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 245, in handle_chld
2020-09-10T03:48:30.512888+00:00 app[web.1]: self.reap_workers()
2020-09-10T03:48:30.512891+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 528, in reap_workers
2020-09-10T03:48:30.512992+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-09-10T03:48:30.513066+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-09-10T03:48:30.580846+00:00 heroku[web.1]: Process exited with status 1
2020-09-10T03:48:30.625801+00:00 heroku[web.1]: State changed from up to crashed

Normally I feel like I can read through the errors and triage them but I don't even know where to start with this one.通常我觉得我可以通读错误并对它们进行分类,但我什至不知道从哪里开始。

Here is my procfile:这是我的 procfile:

web: gunicorn spotlit_due_diligence.spotlit_due_diligence.wsgi:application

Here is my wsgi.py file:这是我的 wsgi.py 文件:

import os
from os.path import abspath, dirname
from sys import path

SITE_ROOT = dirname(dirname(abspath(__file__)))
path.append(SITE_ROOT)

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "jajaja.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.powell")
# from whitenoise.django import DjangoWhiteNoise
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Thanks for any guidance you can provide!感谢您提供的任何指导!

2020-09-10T03:48:30.075258+00:00 app[web.1]: File "/app/spotlit_due_diligence/spotlit_due_diligence/settings/powell.py", line 93, in <module>
2020-09-10T03:48:30.075259+00:00 app[web.1]: os.mkdir('encryption_keys')
2020-09-10T03:48:30.075259+00:00 app[web.1]: OSError: [Errno 17] File exists: 'encryption_keys'

gunicorn starts multiple workers. gunicorn 启动多个工人。 In your code spotlit_due_diligence/spotlit_due_diligence/settings/powell.py line 93 you are creating the folder a folder with os.mkdir('encryption_keys') .在您的代码spotlit_due_diligence/spotlit_due_diligence/settings/powell.py第 93 行中,您正在使用os.mkdir('encryption_keys')创建文件夹。
This runs fine on the first worker run but on the second worker run it will throw an error.这在第一次工作人员运行时运行良好,但在第二次工作人员运行时会引发错误。

You will have to make your code more robust and handle that exception.您将不得不使您的代码更加健壮并处理该异常。 Also not every project is compatible with gunicorn.也不是每个项目都与 gunicorn 兼容。
Are you running your project locally with gunicorn as well?您是否也在使用 gunicorn 在本地运行您的项目? You usually wrap it in gunicorn at the end.你通常在最后用 gunicorn 包裹它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 属性错误开启<module '__main__' when deploying app on heroku via gunicorn< div><div id="text_translate"><p> 决定不为此项目使用自定义 class。</p></div></module> - AttributeError on <module '__main__' when deploying app on Heroku via Gunicorn 部署django应用。 在heroku上(gunicorn,wsgi问题) - Deploying django app. on heroku (gunicorn, wsgi issue) 部署 Python 3 应用 Heroku:崩溃 - Deploying Python 3 App Heroku: Crashing 在将Python应用程序部署到Heroku时出现问题 - Issue deploying Python app to Heroku 在 Heroku 上部署 Postgres Flask 应用程序,“gunicorn.errors.AppImportError:无法在 'app' 中找到属性 'app'。” - Deploying Postgres Flask App on Heroku, "gunicorn.errors.AppImportError: Failed to find attribute 'app' in 'app'." Python /烧瓶/独角兽到Heroku - Python/Flask/Gunicorn to Heroku 在Gunicorn日志中使用Gunicorn和ImportError部署Django应用 - Deploying django app with gunicorn, Importerror in gunicorn log 我正在 Heroku 上部署一个 slack-bolt 应用程序(Procfile: web: gunicorn app:app),但我收到这些错误 - I'm deploying a slack-bolt application on Heroku(Procfile: web: gunicorn app:app), but I get these errors 将 Python Flask 应用程序部署到 Heroku 崩溃 - Deploying Python Flask App to Heroku crashed 在 Heroku 上部署 Nodejs App + Python 时遇到问题 - Trouble deploying Nodejs App + Python on Heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM