【发布时间】:2017-10-20 04:09:36
【问题描述】:
我有一个 python 脚本,practice_one.py,我希望它在 Ubuntu Linux 中永远运行,并且具有以下内容:
while True:
# Code
我尝试了nohup python practice_one.py &,但收到了消息nohup: ignoring input and appending output to ‘nohup.out’。
然后当我按下回车键时,输出另一条消息:[1]+ Exit nohup python practice_one.py
怎么就自动退出了?我可能做错了什么?
编辑
尝试:
nohup python practice_one.py </dev/null &>/dev/null &
然后得到[1] 61122 然后当我按下回车键时我得到[1]+ Exit nohup python practice_one.py </dev/null &>/dev/null &
它曾经可以工作,但现在退出了。现在可能是什么问题?
【问题讨论】:
-
查看
nohup.out是否有任何错误消息。 -
循环体中确实有任何代码,对吧?
-
我将通过在脚本上添加一个 python shebang 来开始解决这个问题,例如
#!/usr/bin/env python。接下来,我将运行这个bash命令以确保该脚本对所有用户都是可执行的:chmod +x practice_one.py。接下来,我会在 shebang 之后但在其他任何内容之前添加一个简单的写入外部文件,例如with open("my_file.txt", "w") as file: file.write("OK"),然后我会尝试再次运行该文件并查看外部文件是否印有“ok”它。如果您尝试这一切,请在此步骤中回复我的结果,以便我可以尝试进一步提供帮助 -
你能把你的脚本贴在某个地方吗?也许可以学到新东西。
-
如果“它以前可以工作,但现在退出了..”,那么问题不可能出在驱动程序上。每个人都在那里做过:-)
标签: python linux python-2.7 ubuntu nohup