-
-
Save windows98SE/4be7abc8ec097626f777a6b2e825f9b1 to your computer and use it in GitHub Desktop.
Async demo python 3.5
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
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()) |
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
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