假设我有一个 for 循环,里面有一个 time.sleep 函数
import time
list = [1, 2, 3]
for i in list:
FunctionThatDoesSomethingTimeRelated(i)
time.sleep(3)
FunctionThatDoesSomethingTimeRelated(i)
有没有办法让循环同时遍历列表的每个部分,而不是等待循环内的代码被执行?
基本上执行顺序需要是这样的:
FunctionThatDoesSomethingTimeRelated(1)
FunctionThatDoesSomethingTimeRelated(2)
FunctionThatDoesSomethingTimeRelated(3)
time.sleep(3)
FunctionThatDoesSomethingTimeRelated(1)
FunctionThatDoesSomethingTimeRelated(2)
FunctionThatDoesSomethingTimeRelated(3)
而不是这个:
FunctionThatDoesSomethingTimeRelated(1)
time.sleep(3)
FunctionThatDoesSomethingTimeRelated(1)
FunctionThatDoesSomethingTimeRelated(2)
time.sleep(3)
FunctionThatDoesSomethingTimeRelated(2)
FunctionThatDoesSomethingTimeRelated(3)
time.sleep(3)
FunctionThatDoesSomethingTimeRelated(3)
qq_遁去的一_1
慕娘9325324
红糖糍粑
慕勒3428872
相关分类