How to run a Python script in the background even

2019-01-08 03:31发布

I have Python script bgservice.py and I want it to run all the time, because it is part of the web service I build. How can I make it run continuously even after I logout SSH?

8条回答
Root(大扎)
2楼-- · 2019-01-08 04:38

You could also use GNU screen which just about every Linux/Unix system should have.

If you are on Ubuntu/Debian, its enhanced variant byobu is rather nice too.

查看更多
Luminary・发光体
3楼-- · 2019-01-08 04:38

The zsh shell has an option to make all background processes run with nohup.

In ~/.zshrc add the lines:

setopt nocheckjobs  #don't warn about bg processes on exit
setopt nohup        #don't kill bg processes on exit

Then you just need to run a process like so: python bgservice.py &, and you no longer need to use the nohup command.

I know not many people use zsh, but it's a really cool shell which I would recommend.

查看更多
登录 后发表回答