Created
June 29, 2015 16:03
-
-
Save memee/66f85aea70f49489eb09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python3.4 | |
import urllib.request | |
import asyncio | |
def return_response(url): | |
return urllib.request.urlopen(url).read() | |
@asyncio.coroutine | |
def read_page(loop, url): | |
print("reading {}".format(url)) | |
data = yield from loop.run_in_executor(None, lambda: return_response(url)) | |
print(data[:100]) | |
if __name__ == '__main__': | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete( | |
asyncio.wait( | |
[ | |
read_page(loop, 'http://www.onet.pl'), | |
read_page(loop, 'http://www.interia.pl'), | |
read_page(loop, 'http://www.wp.pl'), | |
read_page(loop, 'http://www.gazeta.pl'), | |
]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment