2 回答

TA貢獻1810條經驗 獲得超4個贊
您顯示的代碼沒有創(chuàng)建另一個列表,您也可以改進一下:
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個贊
您的代碼中沒有創(chuàng)建新列表。但你可能想縮短一點:
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()
我認為這段代碼很好用;)
添加回答
舉報