Search code examples
pythonherokuheroku-cli

run python console script from heroku


I've deployed a python script on heroku and I can run that in local terminal by

heroku run python script.py

command, But when I close the local terminal the script has been stopped.

Is there a way to run deployed script through the heroku server and independent of local machine ?


Solution

  • Reddy Abel Tintaya Conde's answer using heroku run:detached is good for ad hoc stuff.

    But if your script should run continuously, automatically restarting when it fails, you should define a process for it in your Procfile. Such processes are often called worker processes:

    worker: python script.py
    

    Then you can scale your worker process up (or down) with heroku ps:scale:

    heroku ps:scale worker=1
    

    Whether you run your script this way or via heroku run:detached, remember that this consumes free dyno hours or, if you are using paid dynos, incurs costs.