Skip to content

Commit

Permalink
fix gunicorn.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
ali96343 committed Nov 6, 2023
1 parent 3279540 commit 214c056
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
37 changes: 22 additions & 15 deletions py4web/gunicorn.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
gunicorn
~~~~~~~~
====================
gunicorn with py4web
====================


The gunicorn server starts in the usual way for the py4web

Expand All @@ -8,8 +10,9 @@ The gunicorn server starts in the usual way for the py4web
$./py4web.py run apps -s gunicorn --watch=off
$
$./py4web.py run apps -s gunicornGevent --watch=off
$
$ # gunicornGevent === gunicorn + monkey.patch_all()


gunicornGevent === gunicorn + monkey.patch_all()

It is possible to use several methods to configure gunicorn options with py4web

Expand All @@ -33,10 +36,13 @@ Let's show examples



* set gunicorn options via config file py4web/gunicorn.saenv

* set gunicorn options via config file gunicorn.saenv

::

# example gunicorn.saenv
#
export GUNICORN_worker_tmp_dir=/dev/shm
export GUNICORN_max_requests=1200
worker_class=gthread
Expand All @@ -53,23 +59,23 @@ Let's show examples
# use_python_config=python:mod_name


* set gunicorn options via python file py4web/myguni.conf.py
* set gunicorn options via python file myguni.conf.py

::

set the variable use_python_config=myguni.conf.py
set the env variable use_python_config=myguni.conf.py

.. code:: bash
$ # via env
$export GUNCORN_use_python_config=myguni.conf.py
$
$ # via py4web/gunicorn.saenv
$echo use_python_config=mmyguni.conf.py >> py4web/gunicorn.saenv
$ # via gunicorn.saenv
$echo use_python_config=mmyguni.conf.py >> gunicorn.saenv
::

write file py4web/myguni.conf.py
write file myguni.conf.py

.. code:: python
Expand All @@ -86,7 +92,8 @@ Let's show examples
::

./py4web.py run apps -s gunicorn
$ ./py4web.py run apps -s gunicorn --watch=off


* set gunicorn options via python module

Expand All @@ -97,16 +104,16 @@ Let's show examples
.. code:: bash
$ cd py4web && mkdir mod_name && cp myguni.conf.py mod_name/__init__.py
$ mkdir mod_name && cp myguni.conf.py mod_name/__init__.py
$
$ # via env
$export GUNCORN_use_python_config=python:mod_name
$
$ # via py4web/gunicorn.saenv
$echo use_python_config=python:mod_name >> py4web/gunicorn.saenv
$ # via gunicorn.saenv
$echo use_python_config=python:mod_name >> gunicorn.saenv
::

./py4web.py run apps -s gunicorn
$ ./py4web.py run apps -s gunicorn --watch=off

8 changes: 4 additions & 4 deletions py4web/server_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ def load_config(self):
except KeyError:
pass

if gunicorn_vars:
sa_config.update(gunicorn_vars)
location = gunicorn_vars["config"]
self.logger_info(f"gunicorn: used {location} {sa_config}")
#if gunicorn_vars:
sa_config.update(gunicorn_vars)
location = gunicorn_vars["config"]
self.logger_info(f"gunicorn: used {location} {sa_config}")

for k, v in sa_config.items():
if k not in self.cfg.settings:
Expand Down

0 comments on commit 214c056

Please sign in to comment.