Last active
August 19, 2018 04:42
-
-
Save nhumrich/b53cc1e0482411e4b53d74bd12a485c1 to your computer and use it in GitHub Desktop.
async blog post gevent example
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 gevent.monkey | |
from urllib.request import urlopen | |
gevent.monkey.patch_all() | |
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org'] | |
def print_head(url): | |
print('Starting {}'.format(url)) | |
data = urlopen(url).read() | |
print('{}: {} bytes: {}'.format(url, len(data), data)) | |
jobs = [gevent.spawn(print_head, _url) for _url in urls] | |
gevent.wait(jobs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment