Skip to content

Instantly share code, notes, and snippets.

@khangvan
Created September 28, 2019 04:47
Show Gist options
  • Save khangvan/d084c26527e6643529dc3213a7240664 to your computer and use it in GitHub Desktop.
Save khangvan/d084c26527e6643529dc3213a7240664 to your computer and use it in GitHub Desktop.
python_fetch_paco
#!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