发布时间:2019-09-08 09:14:40编辑:auto阅读(6235)
随机sleep
sleeptime=random.randint(0, 300)
time.sleep(sleeptime)以下为转载http://hi.baidu.com/liuhelishuang/item/1f8cd8f75bd246dd6325d28c
import os
import time
def fun(name):
write_name="command %s failed!\n" % name
print write_name
f = open('/tmp/cs.log','a')
f.write(write_name)
f.close()
def tary(name):
print "the command is %s" % name
command_id = os.system(name)
while command_id != 0:
fun(name)
time.sleep(10)
command_id = os.system(name)
time.sleep(5)
tary("reboot")
Python 编程中使用 time 模块可以让程序休眠
具体方法是time.sleep(秒数),其中“秒数”以秒为单位,可以是小数,0.1秒则代表休眠100毫秒。
# 例1:循环输出休眠1秒
上一篇: 解决python print延迟问题
下一篇: 箱体图Boxplot及Python绘制方
50950
50329
40950
37814
32279
29169
28055
22885
22850
21181
1032°
1714°
1400°
1332°
1594°
1428°
2081°
3623°
3542°
2499°