Created
September 28, 2019 04:47
-
-
Save khangvan/d084c26527e6643529dc3213a7240664 to your computer and use it in GitHub Desktop.
python_fetch_paco
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!pip install paco | |
import paco | |
import aiohttp | |
async def fetch(url): | |
async with aiohttp.ClientSession() as session: | |
async with session.get(url) as res: | |
return res | |
async def fetch_urls(): | |
urls = [ | |
'https://www.google.com', | |
'https://www.yahoo.com', | |
'https://www.bing.com', | |
'https://www.baidu.com', | |
'https://duckduckgo.com', | |
] | |
# Map concurrent executor with concurrent limit of 3 | |
responses = await paco.map(fetch, urls, limit=3) | |
for res in responses: | |
print('Status:', res.status) | |
print('Status:', res.text) | |
# Run in event loop | |
paco.run(fetch_urls()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment