From 6bc3f189e166ae98680a5fc7a114bbfe479755da Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Thu, 1 Dec 2016 15:27:07 -0800 Subject: [PATCH] =?UTF-8?q?Remove=20=E2=80=9CWrappedLogger=E2=80=9D=20-=20?= =?UTF-8?q?does=20not=20do=20anything=20useful?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Never really investigated the reason why ruffus returns a mutex to go along with its logger. It seems that the mutex is only needed if one wanted to make multiple successive calls to a log function and have them appear appear atomically. It is not needed to protect the logger proxy because accessing the proxy triggers IPC in the child process that handles the multiprocessing.Manager() object. The logging wrapper only logs one line at a time, so the mutex does not actually protect logging sequence. Cut it. Also manager.Lock() returns a threading.Lock object so the purpose of it is actually to help processes share a thread-level lock. It would be more appropriate to use a semaphore based multiprocessing.Lock. --- ocrmypdf/__main__.py | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/ocrmypdf/__main__.py b/ocrmypdf/__main__.py index 753a00e6..aebc339e 100755 --- a/ocrmypdf/__main__.py +++ b/ocrmypdf/__main__.py @@ -390,40 +390,8 @@ def logging_factory(logger_name, listargs): return root_logger -class WrappedLogger: - - def __init__(self, my_logger, my_mutex): - self.logger = my_logger - self.mutex = my_mutex - - def log(self, *args, **kwargs): - with self.mutex: - self.logger.log(*args, **kwargs) - - def debug(self, *args, **kwargs): - with self.mutex: - self.logger.debug(*args, **kwargs) - - def info(self, *args, **kwargs): - with self.mutex: - self.logger.info(*args, **kwargs) - - def warning(self, *args, **kwargs): - with self.mutex: - self.logger.warning(*args, **kwargs) - - def error(self, *args, **kwargs): - with self.mutex: - self.logger.error(*args, **kwargs) - - def critical(self, *args, **kwargs): - with self.mutex: - self.logger.critical(*args, **kwargs) - - -_logger, _logger_mutex = proxy_logger.make_shared_logger_and_proxy( +_log, _log_mutex = proxy_logger.make_shared_logger_and_proxy( logging_factory, __name__, [None, options.verbose]) -_log = WrappedLogger(_logger, _logger_mutex) _log.debug('ocrmypdf ' + VERSION)