2 回答
TA贡献1810条经验 获得超4个赞
您显示的代码没有创建另一个列表,您也可以改进一下:
to_remove_states = {CANCEL_REQUESTED, CANCELLED, FAILED, COMPLETED}
def my_filter(taks):
state = ee.data.getTaskStatus(task[0])[0]['state']
if state in to_remove_states:
if state == COMPLETED:
do_something() # should not be dependent on your tasks form download function
return False
return True
def download():
while tasks:
time.sleep(30)
tasks = list(filter(my_filter, tasks))
print('Done!')
download()
TA贡献1836条经验 获得超4个赞
您的代码中没有创建新列表。但你可能想缩短一点:
def download():
while tasks:
for task in tasks[:]:
success = 0
file_name = task[1]
task_index = tasks.index(task)
task_state = ee.data.getTaskStatus(task[0])[0]['state']
print(task, task_state)
if task_state in [CANCEL_REQUESTED, CANCELLED, FAILED, COMPLETED]:
tasks.remove(tasks[task_index])
if task_state == COMPLETED:
do_something()
if tasks:
time.sleep(30)
else:
print('Done!')
download()
我认为这段代码很好用;)
添加回答
举报