运行 Python 使用 ssh 远程作业---我如何注销?

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

我正在通过 ssh 运行宁 Python 脚本 filename.py。一旦我登录到远程机器,我 运行:

python filename.py &

但是,当我关闭终端时,python 似乎停止了 运行ning。为什么是这样?我认为语句末尾的符号 & 意味着程序保持 运行ning?

使用nohup:

nohup python filename.py &

nohup [command] & 将在后台 运行 作业,然后 return 你回到 shell。

我对 shell 中的 python 了解不多,但您可以在 ssh 相关环境中使用屏幕

例如:

sudo apt-get install screen

screen -m

这将创建虚拟 tty (pty)

然后运行你的程序

python prog.py &

希望它对你有用,祝你有个愉快的一天!