New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use argparse with gunicorn #2286
Comments
you can pass app's args through:
|
You may have more success making your custom CLI start Gunicorn from the Python API. Check the documentation on making a custom Gunicorn application: https://docs.gunicorn.org/en/latest/custom.html |
I have the same problem.
|
passing user arguments is not supported. Since applications are handled in a process, it is expected to get custom settings using the environment orotjercustoms ways. Arguments are only there for gunicorn. asimple way to pass custom environement functions from the command line is using the |
Agreed. I'll close this issue. When gunicorn is run with its CLI the command line arguments are for gunicorn. If there are ways we can improve the documentation around how to import gunicorn from your own application, please let us know. We'd be happy to review a PR. |
I'm no longer linked with the app I was developing while creating this issue, so don't have a quick way to check. I'll try to create a small dummy app in this week to verify, but I think that if you use Line 158 in cf55d2c
@benoitc/ @tilgovi , Do you see any immediate issue in this change? |
@yarnabrina that would be a fine way to handle things, but I would rather not make that change in Gunicorn. I think there's some risk that users meant to pass all the arguments to Gunicorn and somewhere there was a mistake. In that case, it might be better to fail fast than silently drop the unknown arguments. |
Hi!
I've come across multiple issues here where people faced problems to use
gunicorn
with their own application, which accepts command line arguments and parses them withargparse
. For all of them, removingargparse
was sufficient to solve the problem.I'm facing the same issue, and I can confirm that instead of passing command line arguments and parsing with
argparse
, if I hardcode the configurations, my application works. But I will have to useargparse
, since I need to run multiple instances of myFlask
application with different configurations.If I don't use
gunicorn
, I run my application as follows:Based on these arguments, I prepare a deep learning model for classification and then finally create a simple
Flask
app to expose thepredict
method. I need to run multiple models for a hierarchical classification problem. So, if I run the above command multiple times (with varying configuration file names), it works fine.But if I try to run with
gunicorn
like this:, then I get the following error:
If I understand correctly, then the
argparse
ofgunicorn
trying to parse these arguments, and those are not passed to theargparse
of my program.But #2125 leads me to believe that it is actually possible to overcome this problem. I tried to follow #1988, but failed. I ran this:
It entered my program alright and reached the step for parsing arguments, but then it showed the following:
Can someone please provide a detailed code example to pass arguments?
Thanks.
The text was updated successfully, but these errors were encountered: