3

I am running a Python script filename.py via ssh. Once I'm logged into the remote machine, I run:

python filename.py &

However, when I close out of the terminal, it appears the python stops running. Why is this? I thought an ampersand & at the end of a statement meant the program kept running?

tripleee
  • 175,061
  • 34
  • 275
  • 318
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
  • Possible duplicate of [Linux: Prevent a background process from being stopped after closing SSH client](http://stackoverflow.com/questions/285015/linux-prevent-a-background-process-from-being-stopped-after-closing-ssh-client) – tripleee Feb 14 '16 at 18:09

2 Answers2

6

Use nohup:

nohup python filename.py &

nohup [command] & will run the job in the background and return you back to the shell.

Alex Woolford
  • 4,433
  • 11
  • 47
  • 80
2

I am not so far into python in shell, but you can use screen in ssh related enviroments

For example:

sudo apt-get install screen

screen -m

This will create virual tty (pty)

Then run your program

python prog.py &

Hope it will work fine for you, have a nice day!

Daniel Mizerski
  • 1,123
  • 1
  • 8
  • 24