0

I have a script that requires 2 two inputs that are not the same every time. So I have to give the input manually every time I run the script. And I do want to deploy this script to Heroku. But unfortunately, I can't give any kind of input manually in heroku:worker. I can't use any kind of environment variables, arguments because these 2 inputs are not static. So heroku:worker just keeps getting the 'There are no inputs' error.

So I have decided to run the script with the command heroku run python3 main.py but no matter what I do I couldn't get out of the terminal without ending the process. I want this script to run continuously even if I get out of the terminal.

So how can I run the python script in Heroku continuously and quit the terminal without breaking the process?

  • Sending the input from the terminal is a bad idea as heroku is not designed for that. you should change your scirpt to accept input via http maybe – Alexander Riedel Nov 12 '20 at 17:09

1 Answers1

0

As Alexander stated Heroku script deploys are not meant to be run frequently like this. It will be worth your time to create a simple Flask server to accept HTTP requests from anywhere (so you can then run your script via CURL or Postman). Heroku also has very good tutorials on how to do this if you are unfamiliar.

However if this is a hard requirement that you cannot deploy a simple web server (even though, you really should), let's work around this:

if you are on OSx or any Unix style machine you can background a process with a simple process script & i.e., heroku run my_script.py & and to call it to the foreground again, just type fg.

I am less familiar with windows but i think you can do start /b <program> but in your case you will be better served by the answer provided here How to run a command in the background on Windows? (if you are running on windows)

Note this is a bad solution and your script will stop running once you close your user session/shut down.

The proper way to be create a web server which takes requests on demand - that way you can pass whatever params you need to whenever you need the script to run.

Karan
  • 1,335
  • 2
  • 14
  • 29