I have a Python script which process data off of a HTTP data stream and I need this script to in theory be running at all times and forever unless I kill it off manually to update it and run it again.
I was wondering what the best practice to do this was on a Unix (Ubuntu in particular) so that even if Terminal is closed etc the script continues to run in the background unless the process or server are shut down?
Thanks
From your question you are implying that you are going to start the script from your terminal and not by any of Linux's startup script management methods like systemd or upstart or init.d scripts.
If you intend to start your script from terminal, and you want it to continue to run after you close your terminal, you need to do two things
1. Make it run in the background by appending '&' after your script.
2. When you close the terminal, the shell associated to it sends HUP signal to all the processes before it dying. To ignore the HUP signal and continue to run in the background you need to start your script with 'nohup'.
tl;dr
Run your script this way:
$ nohup python mypythonscript.py &
Adding your script to rc.local would work, but 'best practice' in my opinion would be to use Upstart. See this post:
Daemon vs Upstart for python script
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With