Metadata download: Make cover check multithreaded

This commit is contained in:
Kovid Goyal 2010-06-24 12:06:34 -06:00
parent bb5ab06f3b
commit 985e65d386

View File

@ -287,9 +287,8 @@ class HeadRequest(urllib2.Request):
def get_method(self):
return "HEAD"
def check_for_covers(items):
def do_cover_check(item):
opener = browser()
for item in items:
item.has_cover = False
try:
opener.open(HeadRequest(OPENLIBRARY%item.isbn), timeout=5)
@ -297,6 +296,11 @@ def check_for_covers(items):
except:
pass # Cover not found
def check_for_covers(items):
threads = [Thread(target=do_cover_check, args=(item,)) for item in items]
for t in threads: t.start()
for t in threads: t.join()
def search(title=None, author=None, publisher=None, isbn=None, isbndb_key=None,
verbose=0):
assert not(title is None and author is None and publisher is None and \