Skip to content
Myr

gevent.rst

This file

Path

docs/deploying/gevent.rst

76 lines · 2.2 KiB

Last changed by

Merge branch 'stable'David Lordbefore adoption798e006

History of this file

Take it

The walk stopped after 200 commits: lines older than 73739a2 point at it.

Merge branch '2.2.x'David Lordbefore adoption73739a2

lines 1–9why, one step back
1gevent
2======34Prefer using :doc:`gunicorn` or :doc:`uwsgi` with gevent workers rather5than using `gevent`_ directly. Gunicorn and uWSGI provide much more6configurable and production-tested servers.78`gevent`_ allows writing asynchronous, coroutine-based code that looks9like standard synchronous Python. It uses `greenlet`_ to enable task

Merge branch 'stable'David Lordbefore adoption798e006

lines 10–11why, one step back
10switching without writing ``async/await`` or using ``asyncio``. This is
11not the same as Python's ``async/await``, or the ASGI server spec.

Merge branch '2.2.x'David Lordbefore adoption73739a2

lines 12–13why, one step back
12
13gevent provides a WSGI server that can handle many connections at once

Merge branch 'stable'David Lordbefore adoption798e006

lines 14–15why, one step back
14instead of one per worker process. See :doc:`/gevent` for more
15information about enabling it in your application.

Merge branch '2.2.x'David Lordbefore adoption73739a2

lines 16–23why, one step back
16
17.. _gevent: https://www.gevent.org/18.. _greenlet: https://greenlet.readthedocs.io/en/latest/192021Installing22----------23

Merge branch 'stable'David Lordbefore adoption798e006

line 24why, one step back
24When using gevent, greenlet>=1.0 is required. When using PyPy,

Merge branch '2.2.x'David Lordbefore adoption73739a2

lines 25–76why, one step back
25PyPy>=7.3.7 is required.
2627Create a virtualenv, install your application, then install ``gevent``.2829.. code-block:: text3031 $ cd hello-app32 $ python -m venv .venv33 $ . .venv/bin/activate34 $ pip install . # install your application35 $ pip install gevent363738Running39-------4041To use gevent to serve your application, write a script that imports its42``WSGIServer``, as well as your app or app factory.4344.. code-block:: python45 :caption: ``wsgi.py``4647 from gevent.pywsgi import WSGIServer48 from hello import create_app4950 app = create_app()51 http_server = WSGIServer(("127.0.0.1", 8000), app)52 http_server.serve_forever()5354.. code-block:: text5556 $ python wsgi.py5758No output is shown when the server starts.596061Binding Externally62------------------6364gevent should not be run as root because it would cause your65application code to run as root, which is not secure. However, this66means it will not be possible to bind to port 80 or 443. Instead, a67reverse proxy such as :doc:`nginx` or :doc:`apache-httpd` should be used68in front of gevent.6970You can bind to all external IPs on a non-privileged port by using71``0.0.0.0`` in the server arguments shown in the previous section. Don't72do this when using a reverse proxy setup, otherwise it will be possible73to bypass the proxy.7475``0.0.0.0`` is not a valid address to navigate to, you'd use a specific76IP address in your browser.