Skip to content

Instantly share code, notes, and snippets.

@ben7th
Created January 14, 2019 04:12
Show Gist options
  • Select an option

  • Save ben7th/e0c297a5346b0c2e7f4ee47386929a8f to your computer and use it in GitHub Desktop.

Select an option

Save ben7th/e0c297a5346b0c2e7f4ee47386929a8f to your computer and use it in GitHub Desktop.
并发异步请求(用于 FC 调度层)
import grequests
import requests
from timeit import default_timer as timer
urls = [ "https://1246105.cn-shenzhen.fc.aliyuncs.com/2016-08-15/proxy/charlene-chatlog/api/bundle/" ] * 10
for idx, url in enumerate(urls):
urls[idx] = urls[idx] + str(idx) + '.xls'
def req_sync():
result = []
for url in urls:
result.append(requests.get(url))
return result
def req_async():
res = [grequests.get(url) for url in urls]
result = grequests.map(res, size=100)
return result
start = timer()
# print(req_sync())
print(req_async())
end = timer()
print(end-start)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment