Skip to content

Instantly share code, notes, and snippets.

@memee
Created June 29, 2015 16:03
Show Gist options
  • Save memee/66f85aea70f49489eb09 to your computer and use it in GitHub Desktop.
Save memee/66f85aea70f49489eb09 to your computer and use it in GitHub Desktop.
#!/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