1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
import timeit
from gevent import monkey; monkey.patch_all()
import gevent
from restkit import *
from restkit.conn import Connection
from socketpool import ConnectionPool
#set_logging("debug")
pool = ConnectionPool(factory=Connection, backend="gevent")
urls = [
"http://refuge.io",
"http://gunicorn.org",
"http://friendpaste.com",
"http://benoitc.io",
"http://couchdb.apache.org"]
allurls = []
for i in range(10):
allurls.extend(urls)
def fetch(u):
r = request(u, follow_redirect=True, pool=pool)
print "RESULT: %s: %s (%s)" % (u, r.status, len(r.body_string()))
def extract():
jobs = [gevent.spawn(fetch, url) for url in allurls]
gevent.joinall(jobs)
t = timeit.Timer(stmt=extract)
print "%.2f s" % t.timeit(number=1)
|