Commit f95e14d3 authored by Denis Bilenko's avatar Denis Bilenko

simplify example concurrent_download.py

- do not use Pool as it's already demoed in dns_mass_resolve.py
parent e0078c70
......@@ -4,24 +4,18 @@
urls = ['http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org']
import gevent
from gevent import monkey
monkey.patch_socket() # patches regular socket to yield to other greenlets
import urllib2
from gevent.pool import Pool
# Pool accepts one optional argument - maximum number of concurrent
# coroutines that can be active at any given moment.
# Try passing 1 or 2 here to see the effect.
pool = Pool()
def print_head(url):
print 'Starting %s' % url
data = urllib2.urlopen(url).read()
print '%s: %s bytes: %r' % (url, len(data), data[:50])
for url in urls:
pool.spawn(print_head, url)
jobs = [gevent.spawn(print_head, url) for url in urls]
pool.join()
gevent.joinall(jobs)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment