Python-为true时每n秒运行一次函数

Python-为true时每n秒运行一次函数,python,time,while-loop,sleep,Python,Time,While Loop,Sleep,我读了很多帖子,但找不到解决其他问题的方法。 我的循环从未停止过。它似乎没有反复检查project.IsInProgress()是否为True 如果我的语句仍然为真,我想每两秒钟检查一次,如果它不再为真,我想中断重复并执行一个print语句 我想问题是它两秒钟都没有运行这个函数。但我不知道如何处理这个问题 check_status = project.IsInProgress() while check_status: print('Render in progress..')

我读了很多帖子,但找不到解决其他问题的方法。 我的循环从未停止过。它似乎没有反复检查project.IsInProgress()是否为True

如果我的语句仍然为真,我想每两秒钟检查一次,如果它不再为真,我想中断重复并执行一个print语句

我想问题是它两秒钟都没有运行这个函数。但我不知道如何处理这个问题

check_status = project.IsInProgress()

while check_status:
    print('Render in progress..')
    time.sleep(2)
else: 
    print('Render is finished')
试试这个:

while project.IsInProgress():
    print('Render in progress..')
    time.sleep(2)
print('Render is finished')
或者,如果您愿意:

check_status = project.IsInProgress()
while check_status:
    print('Render in progress..')
    time.sleep(2)
    check_status = project.IsInProgress()
print('Render is finished')

您的代码在代码开始时只检查一次进行中的循环,如果是真的,循环将永远持续。 要检查每个迭代的状态,请尝试:

while project.IsInProgress() :
    print('Render in progress..')
    time.sleep(2)
else: 
    print('Render is finished')

什么是进步?一个布尔值?是的,这个过程返回一个布尔值,似乎是将它附加到一个变量导致布尔值不刷新。我分配了很多变量,因为我从一个API获得了所有东西。我现在在一行中运行所有函数。我必须将所有函数放在另一行中才能使其工作。非常感谢<代码>GetManager().GetProject().IsRenderingInProgress():