As far as I've been able to tell cookielib isnt thread safe; but then again the post stating so is five years old, so it might be wrong.
Nevertheless, I've been wondering - If I spawn a class like this:
class Acc:
jar = cookielib.CookieJar()
cookie = urllib2.HTTPCookieProcessor(jar)
opener = urllib2.build_opener(cookie)
headers = {}
def __init__ (self,login,password):
self.user = login
self.password = password
def login(self):
return False # Some magic, irrelevant
def fetch(self,url):
req = urllib2.Request(url,None,self.headers)
res = self.opener.open(req)
return res.read()
for each worker thread, would it work? (or is there a better approach?) Each thread would use it's own account; so the fact that workers wouldn't share their cookies is not a problem.