Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

Avoid warning message when running app.

Open cferreirasuazo opened this issue 2 years ago • 1 comments

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?

cferreirasuazo avatar Sep 22 '23 19:09 cferreirasuazo

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.

pUrGe12 avatar Feb 02 '25 19:02 pUrGe12