Skip to content

Instantly share code, notes, and snippets.

@graffic
Created September 9, 2015 16:41
Show Gist options
  • Save graffic/73dbe6172254382178eb to your computer and use it in GitHub Desktop.
Save graffic/73dbe6172254382178eb 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