归结为这里最小的问题是一个简单的 python 脚本,我想在 linux 上使用 nohup 运行它。我使用以下(在 linux 上)运行它:
nohup python test.py &
Run Code Online (Sandbox Code Playgroud)
该命令似乎没有做任何事情,nohup.out 没有附加任何内容。如果我在没有 '&' 的情况下运行它,输出将正确显示在终端窗口上。我错过了什么?
import time
def test():
while(True):
print "Woke up!"
time.sleep(5)
if __name__ == "__main__":
test()
Run Code Online (Sandbox Code Playgroud)
尝试使用命令运行它nohup python -u test.py &
。这应该使输出无缓冲。
您可以通过添加 bang 路径作为带有-u
选项的第一行来使脚本可执行。您还需要使用命令设置可执行位chmod +x test.py
。
#!/usr/bin/python -u
import time
....
Run Code Online (Sandbox Code Playgroud)
然后您可以将其作为nohup test.py &
.
归档时间: |
|
查看次数: |
5298 次 |
最近记录: |