0

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 ?

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

I defined a worker in proc file but the second command gives an error : 'Couldn't find that process type (worker).' whats the number 1 in front of the worker ?
(a) Is your Procfile called Procfile exactly? Not procfile or Procfile.txt or something? (b) Is it in the root (top) irectory of your project? (c) If you're asking about the 1 in heroku ps:scale worker=1, that is the number of dynos we're asking Heroku to scale to. That might be up or down, but we want one running dyno.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.