【发布时间】:2020-02-08 16:55:39
【问题描述】:
等到指定时间
我需要最好的方法来停止程序,直到提到指定的时间(在变量 wait_time 中,小时、分钟、秒的元组)。我曾尝试为此使用 while 循环。但是有没有一种更有效的方法,这样它就不会占用太多的 CPU。等待之后,它会执行一个名为solve() 的函数。
wait_time=(12,10,15)
import time
time_str=time.localtime()
current_time=(time_str.tm_hour,time_str.tm_min,time_str,time_str.tm_sec)
while current_time!=wait_time:
current_time=(time_str.tm_hour,time_str.tm_min,time_str,time_str.tm_sec)
else:
print('Wait time over')
solve()
对于内存部分,我需要一种比这更有效的方法。它应该等到系统时间是给定的时间。
【问题讨论】:
-
你试过用睡眠法吗??
-
这能回答你的问题吗? time.sleep -- sleeps thread or process?
-
你做过研究吗?
标签: python time while-loop wait