Reputation: 21
I've inherited a python django app and am trying to breathe new life in it. It's currently using python 2.7 and many old packages that I will eventually need to upgrade. But the first thing before upgrading is I want to have it running successfully on heroku. So far I have it running fine locally, but I'm running into issues with heroku and 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:
web: gunicorn spotlit_due_diligence.spotlit_due_diligence.wsgi:application
Here is my wsgi.py file:
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!
Upvotes: 0
Views: 343
Reputation: 5330
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. 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')
.
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.
Are you running your project locally with gunicorn as well? You usually wrap it in gunicorn at the end.
Upvotes: 1