I have the following script in Python, each 30 seconds is checking all the tasks in a list, when a task is completed (FAILED, CANCEL or COMPLETED), the task is removed from the original task and then will track again the other tasks. The code is working good in this way.
The problem is that I'm not sure if each iteration of the while loop is creating a new list, because the entire process could take several hours, so I don't want to create unnecessary data in memory.
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 == FAILED:
tasks.remove(tasks[task_index])
elif task_state in [CANCEL_REQUESTED, CANCELLED]:
tasks.remove(tasks[task_index])
elif task_state == COMPLETED:
tasks.remove(tasks[task_index])
success = 1
if success == 1:
do_something()
if tasks:
time.sleep(30)
else:
print('Done!')
download()