gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

ENH: passing parameters to workers via sys.argv

Open sebbASF opened this issue 3 years ago • 0 comments

It would be handy to be able to pass command-line parameters to the worker.

As it stands, the worker has access to sys.argv, but that includes gunicorn options as well. This makes it difficult to parse options. One way would be to drop known gunicorn parameters from sys.argv as they are parsed.

However that suffers from the limitation that misspelt gunicorn options will not be detected, and the worker must use different options from gunicorn.

How about adding a gunicorn option that passes the rest of the command-line to the worker as sys.argv? For example if the option were --params:

python -m gunicorn --bind 127.0.0.1:8080 --timeout=1000 myapp --params --debug --timeout 20 ...

In this case, myapp would see something like [/path/to/myapp, --debug, --timeout, 20] in sys.argv This would be much closer to what myapp would see if run as a main program.

sebbASF avatar Aug 19 '22 13:08 sebbASF