【发布时间】:2016-05-25 12:05:29
【问题描述】:
我正在通过 ssh 运行 Python 脚本 filename.py。一旦我登录到远程机器,我运行:
python filename.py &
但是,当我关闭终端时,python 似乎停止运行。为什么是这样?我认为语句末尾的 & 符号 & 意味着程序继续运行?
【问题讨论】:
我正在通过 ssh 运行 Python 脚本 filename.py。一旦我登录到远程机器,我运行:
python filename.py &
但是,当我关闭终端时,python 似乎停止运行。为什么是这样?我认为语句末尾的 & 符号 & 意味着程序继续运行?
【问题讨论】:
使用nohup:
nohup python filename.py &
nohup [command] & 将在后台运行作业并将您返回到 shell。
【讨论】:
$ nohup: ignoring input and appending output to nohup.out
nohup 的输出默认写入一个名为nohup.out 的文件。如果你想看它运行,你可以tail -f nohup.out。
我对shell中的python不太了解,但是你可以在ssh相关环境中使用screen
例如:
sudo apt-get install screen
screen -m
这将创建虚拟 tty (pty)
然后运行你的程序
python prog.py &
希望它对你有好处,祝你有美好的一天!
【讨论】: