Maintain only two worker processes per CPU core instead of three. This should reduce memory consumption.

This commit is contained in:
Kovid Goyal 2009-07-29 13:21:46 -06:00
parent 65a96f1e5a
commit ba3157ce9f
2 changed files with 17 additions and 1 deletions

View File

@ -1,7 +1,7 @@
''' '''
UI for adding books to the database and saving books to disk UI for adding books to the database and saving books to disk
''' '''
import os import os, shutil
from Queue import Queue, Empty from Queue import Queue, Empty
from PyQt4.Qt import QThread, SIGNAL, QObject, QTimer, Qt from PyQt4.Qt import QThread, SIGNAL, QObject, QTimer, Qt
@ -167,6 +167,15 @@ class Adder(QObject):
self.add_formats(id, formats) self.add_formats(id, formats)
self.number_of_books_added += 1 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): class Saver(QObject):
def __init__(self, parent, db, callback, rows, path, def __init__(self, parent, db, callback, rows, path,

View File

@ -427,6 +427,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
os.path.expanduser('~'))) os.path.expanduser('~')))
if not dir: if not dir:
QCoreApplication.exit(1) QCoreApplication.exit(1)
raise SystemExit(1)
else: else:
self.library_path = dir self.library_path = dir
db = LibraryDatabase2(self.library_path) db = LibraryDatabase2(self.library_path)
@ -522,6 +523,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
@property @property
def spare_server(self): 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: try:
QTimer.singleShot(1000, self.add_spare_server) QTimer.singleShot(1000, self.add_spare_server)
return self.spare_servers.pop() return self.spare_servers.pop()
@ -872,6 +878,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
_('Failed to read metadata from the following')+':', _('Failed to read metadata from the following')+':',
det_msg='\n\n'.join(det_msg), show=True) det_msg='\n\n'.join(det_msg), show=True)
self._adder.cleanup()
self._adder = None self._adder = None