Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a Python job remotely with ssh---how can I log out?

Tags:

python

bash

sh

ssh

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?

like image 543
ShanZhengYang Avatar asked Mar 27 '26 04:03

ShanZhengYang


2 Answers

Use nohup:

nohup python filename.py &

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

like image 82
Alex Woolford Avatar answered Mar 28 '26 17:03

Alex Woolford


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!

like image 22
Daniel Mizerski Avatar answered Mar 28 '26 18:03

Daniel Mizerski