4

私は、concurrent.futures の ThreadPoolExecutor を介してダウンロードする URL のリストを持っていますが、最初の試行がすべて終わった後に再ダウンロードしたいタイムアウト URL がいくつかあるかもしれません。私はそれを行う方法がわかりません、ここに私の試みがありますが、無限の印刷「time_out_again」で失敗しました:

import concurrent.futures

def player_url(url):
    # here. if timeout, return 1. otherwise do I/O and return 0.
    ...

urls = [...]
time_out_futures = [] #list to accumulate timeout urls
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
    future_to_url = (executor.submit(player_url, url) for url in urls)
    for future in concurrent.futures.as_completed(future_to_url):
        if future.result() == 1:
            time_out_futures.append(future)

# here is what I try to deal with all the timeout urls       
while time_out_futures:
    future = time_out_futures.pop()
    if future.result() == 1:
        print('time_out_again')
        time_out_futures.insert(0,future)   # add back to the list

それで、この問題を解決する方法はありますか?

4

1 に答える 1