我有一个 Python 程序,其中包含许多我在 while 循环中调用的函数。
我需要我的 while 循环在它第一次执行循环时调用所有函数,但是我想每两分钟只调用一次其中一个函数。
这是一个代码示例:
def dostuff():
print('I\'m doing stuff!')
def dosthings():
print('I\'m doing things!')
def dosomething():
print('I\'m doing something!')
if __name__ == '__main__':
while True:
dostuff()
print('I did stuff')
dosthings()
print('I did things') #this should run once every X seconds, not on all loops
dosomething()
print('I did something')
我怎样才能达到这个结果?我必须使用多线程/多处理吗?