I'm trying to deploy a python web application on Heroku using the following Procfile command:
web: gunicorn service:app --log-file=- --workers 1 --threads 4
This generates the following error:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 139, in load_class
mod = import_module('.'.join(components))
File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/gthread.py", line 37, in <module>
""")
RuntimeError:
You need 'concurrent' installed to use this worker with this python version.
As we do not control the gunicorn installation on Heroku, how do I resolve this dependency issue?
Oddly, Heroku do not mention gunicorn threads in their docs, only workers. Is this related?
Gunicorn is a python WSGI HTTP server that will serve your Flask application at heroku.
Gunicorn is a pure-Python HTTP server for WSGI applications. It allows you to run any Python application concurrently by running multiple Python processes within a single dyno. It provides a perfect balance of performance, flexibility, and configuration simplicity.
Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork worker model ported from Ruby's Unicorn project. The Gunicorn server is broadly compatible with various web frameworks, simply implemented, light on server resources, and fairly speedy.
Green Unicorn, commonly shortened to "Gunicorn", is a Web Server Gateway Interface (WSGI) server implementation that is commonly used to run Python web applications.
Add these lines to your requirements.txt:
futures==2.1.6
trollius==1.0.1
After pushing these changes to your heroku instance you will be able to run gunicorn with threads.
concurrent is a python 3.2 package and is backported to python 2.7 as future package. You should either use at least python 3.2 as your runtime or you should add the backported packages to your project requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With