questions about multiprocessing
Vincent Ren
renws1990 at gmail.com
Sun Mar 6 22:53:56 EST 2011
I've got some new problems and I tried to search on Google but got no
useful information.
I want to download some images with multiprocessing.pool
In my class named Renren, I defined two methods:
def getPotrait(self, url):
# get the current potraits of a friend on Renren.com
try:
r = urllib2.urlopen(url)
except urllib2.URLError:
print "Time out"
tmp = re.search('large_[\d\D]*.jpg', url)
image_name = tmp.group()
img = r.read()
output = open(image_name, 'wb')
output.write(img)
output.close()
def getLargePotraits(self):
tasks = self.makeTaskList()
pool = Pool(processes = 3)
pool.map(self.getPotrait, tasks)
tasks is a list of URLs of images, I want to download these images and
save them locally.
In another python file, I wrote this:
from renren import Renren
# get username and password for RenRen.com
username = raw_input('Email: ')
password = raw_input('Password: ')
print
a = Renren(username, password)
a.login()
a.getLargePotraits()
However, when I try to run this file, I received an error message:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 532, in
__bootstrap_inner
self.run()
File "/usr/lib/python2.6/threading.py", line 484, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in
_handle_tasks
put(task)
PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup
__builtin__.instancemethod failed
More information about the Python-list
mailing list