From: Marcin Koziej Date: Wed, 9 Nov 2011 09:13:28 +0000 (+0100) Subject: log parallel job exceptions X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/9e65086e2b3ab261138a95bfe8b2a17947c630dd?ds=sidebyside log parallel job exceptions --- diff --git a/apps/search/index.py b/apps/search/index.py index 5ebae2c42..2ae909a84 100644 --- a/apps/search/index.py +++ b/apps/search/index.py @@ -22,7 +22,7 @@ import catalogue.models from multiprocessing.pool import ThreadPool from threading import current_thread import atexit - +import traceback class WLAnalyzer(PerFieldAnalyzerWrapper): def __init__(self): @@ -247,6 +247,17 @@ class Index(IndexStore): self.close() +def log_exception_wrapper(f): + def _wrap(*a): + try: + f(*a) + except Exception, e: + print("Error in indexing thread: %s" % e) + traceback.print_exc() + raise e + return _wrap + + class ReusableIndex(Index): """ Works like index, but does not close/optimize Lucene index @@ -271,7 +282,7 @@ class ReusableIndex(Index): atexit.register(ReusableIndex.close_reusable) def index_book(self, *args, **kw): - job = ReusableIndex.pool.apply_async(Index.index_book, (self,) + args, kw) + job = ReusableIndex.pool.apply_async(log_exception_wrapper(Index.index_book), (self,) + args, kw) ReusableIndex.pool_jobs.append(job) @staticmethod