我的程序需要从API中获取一些数据,但是时间间隔是恒定的,每60秒只有6秒。在没有停止的情况下运行一个while循环是CPU强度太大,我不想那样做。
while loop:
candles = get_candles(ACTIVE, TIMEFRAME, 6, time())
# get data while the loop is running
....我所需要的是停止循环60秒,并运行循环从秒57到秒3在每60秒。我需要的所有数据都是在这6秒的间隔内。
例如,从14:00:57到14:01:03,我检索数据,其余时间,函数等待。
这有可能吗?
发布于 2022-03-27 00:17:54
import time
start = time.time()
while loop:
check = time.time()
candles = get_candles(ACTIVE, TIMEFRAME, 6, time())
if check - start >= 6:
time.sleep(54)
start = time.time()https://stackoverflow.com/questions/71631346
复制相似问题