Python2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import os import time def print_ts(message): print "[%s] %s"%(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message) def run(interval, command): print_ts("-"*100) print_ts("Command %s"%command) print_ts("Starting every %s seconds."%interval) print_ts("-"*100) while True: try: # sleep for the remaining seconds of interval time_remaining = interval-time.time()%interval print_ts("Sleeping until %s (%s seconds)..."%((time.ctime(time.time()+time_remaining)), time_remaining)) time.sleep(time_remaining) print_ts("Starting command.") # execute the command status = os.system(command) print_ts("-"*100) print_ts("Command status = %s."%status) except Exception, e: print e if __name__=="__main__": interval = 5 command = r"ls" run(interval, command) |
Python3:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import os import time def print_ts(message): print("[%s] %s"%(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), message)) def run(interval, command): print_ts("-"*100) print_ts("Command %s"%command) print_ts("Starting every %s seconds."%interval) print_ts("-"*100) while True: try: # sleep for the remaining seconds of interval time_remaining = interval-time.time()%interval print_ts("Sleeping until %s (%s seconds)..."%((time.ctime(time.time()+time_remaining)), time_remaining)) time.sleep(time_remaining) print_ts("Starting command.") # execute the command status = os.system(command) print_ts("-"*100) print_ts("Command status = %s."%status) except Exception as e: print(e) if __name__=="__main__": interval = 5 command = r"python3 tmp.py" run(interval, command) |
本文最后更新于2021年3月18日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
最新评论
大佬 http://ffflyy22.xyz/apps/fly.html 这是我试着创的站 但苹果手机安装后 执行都卡死 想请问是哪边出问题 可以的话 我提供网页编码寄给您 跪求协助…
马大佬您好 自己弄了一个苹果站 但测试安装不能用 连夏时也没法 能否与您交流下呢 我邮箱 ghostchat1@protonmail.com 跪求大佬T.T
该评论为私密评论
该评论为私密评论
该评论为私密评论
大佬 误传了一个文件 可以帮忙删除一下吗
aaaaa 我
我的也是