From ba3157ce9faf2f0e7d62344bf411697c9f35d988 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 29 Jul 2009 13:21:46 -0600 Subject: [PATCH] Maintain only two worker processes per CPU core instead of three. This should reduce memory consumption. --- src/calibre/gui2/add.py | 11 ++++++++++- src/calibre/gui2/main.py | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/add.py b/src/calibre/gui2/add.py index 49aa624e12..6ccf33c5c8 100644 --- a/src/calibre/gui2/add.py +++ b/src/calibre/gui2/add.py @@ -1,7 +1,7 @@ ''' UI for adding books to the database and saving books to disk ''' -import os +import os, shutil from Queue import Queue, Empty from PyQt4.Qt import QThread, SIGNAL, QObject, QTimer, Qt @@ -167,6 +167,15 @@ class Adder(QObject): self.add_formats(id, formats) self.number_of_books_added += 1 + def cleanup(self): + if hasattr(self, 'worker') and hasattr(self.worker, 'tdir') and \ + self.worker.tdir is not None: + if os.path.exists(self.worker.tdir): + try: + shutil.rmtree(self.worker.tdir) + except: + pass + class Saver(QObject): def __init__(self, parent, db, callback, rows, path, diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index adf2f5b8de..a6a2e90e18 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -427,6 +427,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): os.path.expanduser('~'))) if not dir: QCoreApplication.exit(1) + raise SystemExit(1) else: self.library_path = dir db = LibraryDatabase2(self.library_path) @@ -522,6 +523,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): @property def spare_server(self): + # Because of the use of the property decorator, we're called one + # extra time. Ignore. + if not hasattr(self, '__spare_server_property_limiter'): + self.__spare_server_property_limiter = True + return None try: QTimer.singleShot(1000, self.add_spare_server) return self.spare_servers.pop() @@ -872,6 +878,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): _('Failed to read metadata from the following')+':', det_msg='\n\n'.join(det_msg), show=True) + self._adder.cleanup() self._adder = None