I have a Python Flask app on Heroku that serves web pages but also allows certain tasks to be launched which I believe would be best structured as background tasks. As such
You could use a process manager such as god or monit.
With god, you can set up your configuration like so
God.watch do |w|
w.name = "app"
w.start = "python app.py"
w.keepalive
end
God.watch do |w|
w.name = "worker"
w.start = "python worker.py"
w.keepalive
end
Then you put this in your Procfile
god -c path/to/config.god -D
By default, it automatically restarts the process if it crashes, and you can configure it to restart the app if memory usage gets too high. Check out the documentation.