Skip to content
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

Avoid warning message when running app. #741

Open
cferreirasuazo opened this issue Sep 22, 2023 · 1 comment
Open

Avoid warning message when running app. #741

cferreirasuazo opened this issue Sep 22, 2023 · 1 comment
Assignees

Comments

@cferreirasuazo
Copy link

Hello, I'm testing the application and I want to run the API in a production environment.

python nettacker.py --start-api --api-host 0.0.0.0  --api-access-key HERECOMESTHESECRETKEY

how can i run this command with gunicorn in production?

@securestep9 securestep9 self-assigned this Oct 23, 2023
@pUrGe12
Copy link
Contributor

pUrGe12 commented Feb 2, 2025

Hey there! As far as I am aware you can run such a script using a subprocess as well. So if for example you're trying to host your backend on render, then you can create a subprocess that runs this code in the server in a file named app like

from flask import Flask
import subprocess

app = Flask(__name__)

@app.route('/start-api', methods=['GET'])
def start_api():
    subprocess.Popen(['python3', 'nettacker.py', '--start-api', '--api-host', '0.0.0.0', '--api-access-key', 'HERECOMESTHESECRETKEY'])
    return 'started', 200

if __name__ == "__main__":
    app.run()

and call gunicorn as such (adjust the -w value to the number of workers you want, based on traffic)

gunicorn -w 4 -b 0.0.0.0:8000 app:app

So, in that case all you will have to do is trigger the /start-api endpoint and you're good to go.

Does this make sense? Please let me know if you have any further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants