Run h24 a python script

Hi,
I’m wondering how to run h24/7 a python script. When I close the terminal, the script stops running.
Thanks :smiley:

You could use a glitch.json file’s start command to trigger the script which would keep it running as long as the container is running. The container will sleep after 5 minutes unless you pay to have it Boosted in which case it would run 24/7.

How do I do this?
Thanks for helping ^^

I tried
{ start: "python3 starter.py" } but it says me errors

This has the closet thing to official documentation for the glitch.json file. Give that a look over and if that doesn’t make sense let us know.

Ok, I don’t really know how to use JSON files, but on the console I have this:
* Tip: There are .env or .flaskenv files present. Do “pip install python-dotenv” to use them.
* Serving Flask app “server” (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

I guess it’s ok?
I didn’t did any .json files, I just did a start.sh and a requirements.txt

When I go on the page, it says start up for ever

Oh! I see what’s happening here, you should set up a WSGI server like gunicorn or waitress to run as an intermediary for your Flask app: https://flask.palletsprojects.com/en/1.1.x/deploying/wsgi-standalone/

You’ll use the start.sh to run the gunicorn myproject:app command.

Oh, by searching in some source codes in projects, I saw this:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
  return "Hello World!"

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

I need this?
By the way, I don’t know if this is normal

$ gunicorn 
-su: gunicorn: command not found

Ok, it works now, but the website doesn’t respond. The page doesn’t load.
EDIT: Site didn’t respond

Something in the code caused it to close the connection before providing a response.

If this is your project please visit us at support.glitch.com for assistance.

Gunicorn is another python package, you install it with pip (or pip3) install gunicorn.

If you link to your project we might be able to better help you with the error.

1 Like

Hi, thanks for trying to help me, but I found the solution:

{
  "install": "pip3 install --user -r requirements.txt",
  "start": "PYTHONUNBUFFERED=true python3 server.py",
  
  "watch": {
"ignore": [
  "\\.pyc$"
],
"install": {
  "include": [
    "^requirements\\.txt$"
  ]
},
"restart": {
  "include": [
    "\\.py$",
    "^start\\.sh"
  ]
},
"throttle": 15000
  }
}
1 Like

@Showdown76 just remember, there is a limit of 20 projects you can run 24/7 before you get affected by quota limits

Ok, but I need to run only 2-4 projects 24/7 so it’s ok