From 1fb6ff09f6908564db70196772d9d9b96f1876bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chujun=20Chen=F0=9F=8D=AD?= Date: Mon, 12 Feb 2024 10:54:45 -0800 Subject: [PATCH] feat!: enable timeout default timeout settings is 5 min, same as Cloud run; change default behavior from multi-threads to multi-workesr to avoid zombie timeout settings; allow user customization to workers/threads by assigning env var; noted that timeout won't work when #thread > 1. --- src/functions_framework/_http/gunicorn.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/functions_framework/_http/gunicorn.py b/src/functions_framework/_http/gunicorn.py index 3a9c545b..009a06b7 100644 --- a/src/functions_framework/_http/gunicorn.py +++ b/src/functions_framework/_http/gunicorn.py @@ -21,14 +21,15 @@ class GunicornApplication(gunicorn.app.base.BaseApplication): def __init__(self, app, host, port, debug, **options): self.options = { "bind": "%s:%s" % (host, port), - "workers": 1, - "threads": (os.cpu_count() or 1) * 4, - "timeout": 0, + "workers": os.environ.get("WORKERS", (os.cpu_count() or 1) * 4), + "threads": os.environ.get("THREADS", 1), + "timeout": os.environ.get("CLOUD_RUN_TIMEOUT_SECONDS", 300), "loglevel": "error", "limit_request_line": 0, } self.options.update(options) self.app = app + super().__init__() def load_config(self):