Skip to content
Myr

eventlet.rst

This file

Path

docs/deploying/eventlet.rst

80 lines · 2.3 KiB

Last changed by

Merge branch '2.2.x'David Lordbefore adoptioncfa863c

History of this file

Take it

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 1–36why, one step back
1eventlet
2========34Prefer using :doc:`gunicorn` with eventlet workers rather than using5`eventlet`_ directly. Gunicorn provides a much more configurable and6production-tested server.78`eventlet`_ allows writing asynchronous, coroutine-based code that looks9like standard synchronous Python. It uses `greenlet`_ to enable task10switching without writing ``async/await`` or using ``asyncio``.1112:doc:`gevent` is another library that does the same thing. Certain13dependencies you have, or other considerations, may affect which of the14two you choose to use.1516eventlet provides a WSGI server that can handle many connections at once17instead of one per worker process. You must actually use eventlet in18your own code to see any benefit to using the server.1920.. _eventlet: https://eventlet.net/21.. _greenlet: https://greenlet.readthedocs.io/en/latest/222324Installing25----------2627When using eventlet, greenlet>=1.0 is required, otherwise context locals28such as ``request`` will not work as expected. When using PyPy,29PyPy>=7.3.7 is required.3031Create a virtualenv, install your application, then install32``eventlet``.3334.. code-block:: text3536 $ cd hello-app

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

lines 37–38why, one step back
37 $ python -m venv .venv
38 $ . .venv/bin/activate

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 39–46why, one step back
39 $ pip install . # install your application
40 $ pip install eventlet414243Running44-------4546To use eventlet to serve your application, write a script that imports

Merge remote-tracking branch 'origin/2.1.x'David Lordbefore adoption96d39c8

line 47why, one step back
47its ``wsgi.server``, as well as your app or app factory.

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 48–56why, one step back
48
49.. code-block:: python50 :caption: ``wsgi.py``5152 import eventlet53 from eventlet import wsgi54 from hello import create_app5556 app = create_app()

Merge branch '2.2.x'David Lordbefore adoptioncfa863c

line 57why, one step back
57 wsgi.server(eventlet.listen(("127.0.0.1", 8000)), app)

Merge branch '2.1.x'David Lordbefore adoption9139af1

lines 58–80why, one step back
58
59.. code-block:: text6061 $ python wsgi.py62 (x) wsgi starting up on http://127.0.0.1:8000636465Binding Externally66------------------6768eventlet should not be run as root because it would cause your69application code to run as root, which is not secure. However, this70means it will not be possible to bind to port 80 or 443. Instead, a71reverse proxy such as :doc:`nginx` or :doc:`apache-httpd` should be used72in front of eventlet.7374You can bind to all external IPs on a non-privileged port by using75``0.0.0.0`` in the server arguments shown in the previous section.76Don't do this when using a reverse proxy setup, otherwise it will be77possible to bypass the proxy.7879``0.0.0.0`` is not a valid address to navigate to, you'd use a specific80IP address in your browser.