Skip to content

Instantly share code, notes, and snippets.

@windows98SE
Forked from graffic/async.py
Created October 14, 2017 21:23
Show Gist options
  • Save windows98SE/4be7abc8ec097626f777a6b2e825f9b1 to your computer and use it in GitHub Desktop.
Save windows98SE/4be7abc8ec097626f777a6b2e825f9b1 to your computer and use it in GitHub Desktop.
Async demo python 3.5
import aiohttp
import asyncio
async def get(index):
response = await aiohttp.get('http://httpbin.org/delay/%d' % index)
print(index, "Done")
response.close()
async def doMany():
coros = []
for i in range(5):
coro = get(i)
coros.append(coro)
await asyncio.gather(*coros)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(doMany())
import requests
def get(index):
response = requests.get('http://httpbin.org/delay/%d' % index)
print(index, "Done")
response.close()
def doMany():
for i in range(5):
get(i)
if __name__ == "__main__":
doMany()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment