From 288905ee34c23736c15f83a16d819f3f52bf27c0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 27 Mar 2011 10:59:38 -0600 Subject: [PATCH] Windows build: Try clearing the zipimport cache if importing modules in the worker process fails --- src/calibre/utils/ipc/worker.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/ipc/worker.py b/src/calibre/utils/ipc/worker.py index 9594f64ae4..a891d09f3d 100644 --- a/src/calibre/utils/ipc/worker.py +++ b/src/calibre/utils/ipc/worker.py @@ -12,6 +12,8 @@ from threading import Thread from Queue import Queue from contextlib import closing from binascii import unhexlify +from zipimport import ZipImportError + from calibre import prints from calibre.constants import iswindows, isosx @@ -75,7 +77,14 @@ class Progress(Thread): def get_func(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) return func, notification