Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gunicorn threads on Heroku

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?

like image 622
Jonathan Livni Avatar asked Sep 04 '14 12:09

Jonathan Livni


People also ask

Does heroku use Gunicorn?

Gunicorn is a python WSGI HTTP server that will serve your Flask application at heroku.

What is Gunicorn in 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.

What is Gunicorn Wsgi?

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.

Is Gunicorn a Web server?

Green Unicorn, commonly shortened to "Gunicorn", is a Web Server Gateway Interface (WSGI) server implementation that is commonly used to run Python web applications.


1 Answers

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.

like image 160
mehdix Avatar answered Oct 11 '22 10:10

mehdix