我需要在无限循环中永远运行我的 Python 程序..
目前我是这样运行的 -
#!/usr/bin/python
import time
# some python code that I want
# to keep on running
# Is this the right way to run the python program forever?
# And do I even need this time.sleep call?
while True:
time.sleep(5)
有没有更好的方法呢?还是我什至需要 time.sleep
电话?
有什么想法吗?
最佳答案
是的,您可以使用永不中断的 while True:
循环来持续运行 Python 代码。
但是,您需要将要连续运行的代码放入循环中:
#!/usr/bin/python
while True:
# some python code that I want
# to keep on running
另外,time.sleep
用于暂停脚本的操作一段时间。所以,既然你想让你的持续运行,我不明白你为什么要使用它。
关于python - 如何永远运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20170251/