Python - 运行 为真时每 n 秒运行一次
Python - Run function every n second while true
我阅读了很多帖子,但找不到适用于 else 条件的解决方案。
可悲的是,我的循环从未停止过。似乎没有反复检查 project.IsInProgress() = True
如果我的语句仍然为真,我想每两秒检查一次,如果它不再为真,我想打破重复并执行打印语句。
我想问题是它不是 运行 每两秒一次的函数。但我不知道如何处理这个问题。
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')
我阅读了很多帖子,但找不到适用于 else 条件的解决方案。 可悲的是,我的循环从未停止过。似乎没有反复检查 project.IsInProgress() = True
如果我的语句仍然为真,我想每两秒检查一次,如果它不再为真,我想打破重复并执行打印语句。
我想问题是它不是 运行 每两秒一次的函数。但我不知道如何处理这个问题。
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')