Skip to content

Commit

Permalink
check empty env gunicorn_vars
Browse files Browse the repository at this point in the history
  • Loading branch information
ali96343 committed Oct 25, 2023
1 parent bde0901 commit a9f9200
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions py4web/server_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class GunicornServer(ServerAdapter):
# https://pawamoy.github.io/posts/unify-logging-for-a-gunicorn-uvicorn-app/
# ./py4web.py run apps -s gunicorn --watch=off --port=8000 --ssl_cert=cert.pem --ssl_key=key.pem -w 6 -Q

def run(self, py4web_apps_handler):
def run(self, app_handler):
from gunicorn.app.base import BaseApplication

level = check_level (self.options["logging_level"])
Expand All @@ -152,25 +152,29 @@ def run(self, py4web_apps_handler):
"errorlog": log_to,
})

# export GUNICORN_WORKERS=2
# export GUNICORN_BACKLOG=4096

gunicorn_env = dict()
for k,v in os.environ.items():
if k.startswith("GUNICORN_"):
key = k.split('_', 1)[1].lower()
gunicorn_env[key] = v
config.update( gunicorn_env )
if level == logging.NOTSET:
print (config)

class GunicornApplication(BaseApplication):
def load_config(self):

# export GUNICORN_WORKERS=2
# export GUNICORN_BACKLOG=4096

gunicorn_vars = dict()

for k,v in os.environ.items():
if k.startswith("GUNICORN_"):
key = k.split('_', 1)[1].lower()
if v:
gunicorn_vars[key] = v

if gunicorn_vars:
config.update( gunicorn_vars )
print ('gunicorn config:',config)

for key, value in config.items():
self.cfg.set(key, value)

def load(self):
return py4web_apps_handler
return app_handler

GunicornApplication().run()
return GunicornServer
Expand Down

0 comments on commit a9f9200

Please sign in to comment.