Windows build: Try clearing the zipimport cache if importing modules in the worker process fails

This commit is contained in:
Kovid Goyal 2011-03-27 10:59:38 -06:00
parent ae1c331d3c
commit 288905ee34

View File

@ -12,6 +12,8 @@ from threading import Thread
from Queue import Queue from Queue import Queue
from contextlib import closing from contextlib import closing
from binascii import unhexlify from binascii import unhexlify
from zipimport import ZipImportError
from calibre import prints from calibre import prints
from calibre.constants import iswindows, isosx from calibre.constants import iswindows, isosx
@ -75,7 +77,14 @@ class Progress(Thread):
def get_func(name): def get_func(name):
module, func, notification = PARALLEL_FUNCS[name] module, func, notification = PARALLEL_FUNCS[name]
module = importlib.import_module(module) try:
module = importlib.import_module(module)
except ZipImportError:
# Something windows weird happened, try clearing the zip import cache
# incase the zipfile was changed from under us
from zipimport import _zip_directory_cache as zdc
zdc.clear()
module = importlib.import_module(module)
func = getattr(module, func) func = getattr(module, func)
return func, notification return func, notification