前端运行python脚本_如何永远运行Python程序?

I need to run my Python program forever in an infinite loop..

Currently I am running it like this -

#!/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)

Is there any better way of doing it? Or do I even need time.sleep call?

Any thoughts?

解决方案

Yes, you can use a while True: loop that never breaks to run Python code continually.

However, you will need to put the code you want to run continually inside the loop:

#!/usr/bin/python

while True:

# some python code that I want

# to keep on running

Also, time.sleep is used to suspend the operation of a script for a period of time. So, since you want yours to run continually, I don't see why you would use it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值