Home > Mobile >  run python console script from heroku
run python console script from heroku

Time:02-19

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 ?

CodePudding user response:

You can check:

https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-run-detached

heroku run:detached -t python script.py should do the trick for you

CodePudding user response:

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.

  • Related