Skip to content

Instantly share code, notes, and snippets.

@szaydel
Created February 28, 2013 21:20
Show Gist options
  • Save szaydel/5060224 to your computer and use it in GitHub Desktop.
Save szaydel/5060224 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
from pykka.actor import Actor
import pykka
import urllib
class Fetcher(Actor):
def fetch(self, url):
return urllib.urlopen(url).read()
class FetcherPool(Actor):
def __init__(self, pool_size):
self.pool = []
self.next = -1
self.pool_size = pool_size
for i in range(pool_size):
self.pool.append(Fetcher.start_proxy())
def get_next(self):
self.next = (self.next + 1) % self.pool_size
return self.next
def fetch(self, url):
i = self.get_next()
future = self.pool[i].fetch(url)
return future
pool = FetcherPool.start_proxy(10)
urls = []
for i in range(100):
urls.append(pool.fetch("http://thecelebritycafe.com/features/22477.html"))
urls[-1].get().wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment