Skip to content

Instantly share code, notes, and snippets.

@nhumrich
Last active August 19, 2018 04:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nhumrich/b53cc1e0482411e4b53d74bd12a485c1 to your computer and use it in GitHub Desktop.
Save nhumrich/b53cc1e0482411e4b53d74bd12a485c1 to your computer and use it in GitHub Desktop.
async blog post gevent example
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