How to limit concurrency with Python asyncio?

后端 未结 5 1253
我在风中等你
我在风中等你 2020-11-27 02:35

Let\'s assume we have a bunch of links to download and each of the link may take a different amount of time to download. And I\'m allowed to download using utmost 3 connecti

5条回答
  •  甜味超标
    2020-11-27 03:18

    The asyncio-pool library does exactly what you need.

    https://pypi.org/project/asyncio-pool/

    
    LIST_OF_URLS = ("http://www.google.com", "......")
    
    pool = AioPool(size=3)
    await pool.map(your_download_coroutine, LIST_OF_URLS)
    

提交回复
热议问题