【发布时间】:2016-03-04 03:09:34
【问题描述】:
我有一个执行 post 函数的 try 循环,它需要一些时间才能工作:
def recalc_proj(proj):
for x in range(0,10):
while True:
try:
newproj = proj.post('docs/recalc')
except someError:
print "another job is running. waiting 10s"
time.sleep(10)
continue
break
print "SUCCESS"
我只想运行一次newproj = proj.post('docs/recalc'),如果运行没有错误,退出。
但是,在运行上面的函数之后,我在屏幕上得到了这个输出:
another job is running. waiting 10s
another job is running. waiting 10s
another job is running. waiting 10s
another job is running. waiting 10s
SUCCESS
another job is running. waiting 10s
another job is running. waiting 10s
another job is running. waiting 10s
为什么即使在我需要的代码行成功运行后它仍继续循环?我认为 break 意味着退出 for 循环?
【问题讨论】:
标签: python for-loop while-loop try-catch