我有一个python程序需要全天候运行。它有10%的时间在30秒的间隔内睡着。有没有办法让程序安全地停止并重新启动,以便只在睡眠期间重新启动?你知道吗
以下是代码示例main()
函数和实现:
# =============================================================================
# MAIN
# =============================================================================
def main():
while True:
checkReply = Reply()
checkReply.time_to_reply()
checkReply.search_db()
time.sleep(10)
# =============================================================================
# RUNNER
# =============================================================================
print "start"
if __name__ == '__main__':
main()
一种方法是将main()更改为以下内容:
为了增加学分,可以使用https://pypi.python.org/pypi/python-daemon/之类的东西使程序在启动时进行后台监控。你知道吗
然后,要在下次睡眠时重新启动程序,只需触摸重新启动文件。您可以在配置文件中将其路径设置为任何您喜欢的路径。你知道吗
相关问题 更多 >
编程相关推荐