Memory usage with concurrent.futures.ThreadPoolExecutor in Python3

前端 未结 4 1390
盖世英雄少女心
盖世英雄少女心 2021-02-05 21:42

I am building a script to download and parse benefits information for health insurance plans on Obamacare exchanges. Part of this requires downloading and parsing the plan benef

4条回答
  •  离开以前
    2021-02-05 22:47

    As an alternative solution, you can call add_done_callback on your futures and not use as_completed at all. The key is NOT keeping references to futures. So future_to_url list in original question is a bad idea.

    What I've done is basically:

    def do_stuff(future):
        res = future.result()  # handle exceptions here if you need to
    
    f = executor.submit(...)
    f.add_done_callback(do_stuff)
    

提交回复
热议问题