From 38007ab3d52225ddacc8c016dc5f0a81844ae217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jastrz=C4=99bski?= Date: Wed, 6 Nov 2013 11:08:14 +0100 Subject: [PATCH] Number of KindleGen threads is now dynamic --- README.md | 3 ++- kcc/KCC_gui.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4441ed4..26b07f5 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,9 @@ You can find the latest released binary at the following links: ### For compiling/running from source: - Python 2.7 - Included in MacOS and Linux, follow the [official documentation](http://www.python.org/getit/windows/) to install on Windows. -- PyQt4 - Please refer to official documentation for installing into your system. +- [PyQt4](http://www.riverbankcomputing.co.uk/software/pyqt/download) - Please refer to official documentation for installing into your system. - [Pillow](http://pypi.python.org/pypi/Pillow/) 2.2.1+ - For comic optimizations. Please refer to official documentation for installing into your system. +- [Psutil](https://code.google.com/p/psutil/) - Please refer to official documentation for installing into your system. - **To build OS X release a modified QT is required:** [Patch](https://github.com/ciromattia/kcc/blob/master/other/QT-4.8.5-QListWidget.patch) ## USAGE diff --git a/kcc/KCC_gui.py b/kcc/KCC_gui.py index c183abb..db1f1b3 100644 --- a/kcc/KCC_gui.py +++ b/kcc/KCC_gui.py @@ -32,6 +32,7 @@ import comic2ebook import kindlesplit import socket import string +from psutil import virtual_memory from KCC_rc_web import WebContent from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from SocketServer import ThreadingMixIn @@ -265,11 +266,17 @@ class WorkerThread(QtCore.QThread): self.errors = False self.kindlegenErrorCode = [0] self.workerOutput = [] - # 4 should be safe value. It will not melt 32bit enviroments and machines with pathologically low amount of RAM. - if QtCore.QThread.idealThreadCount() < 4: - self.threadNumber = QtCore.QThread.idealThreadCount() + # Let's make sure that we don't fill the memory + availableMemory = virtual_memory()[0]/1000000000 + if availableMemory <= 2: + self.threadNumber = 1 + elif 2 < availableMemory <= 4: + self.threadNumber = 2 else: self.threadNumber = 4 + # Let's make sure that we don't use too many threads + if self.threadNumber > QtCore.QThread.idealThreadCount(): + self.threadNumber = QtCore.QThread.idealThreadCount() def __del__(self): self.wait() @@ -380,6 +387,7 @@ class WorkerThread(QtCore.QThread): self.emit(QtCore.SIGNAL("progressBarTick")) self.emit(QtCore.SIGNAL("addMessage"), 'Creating MOBI file...', 'info') self.workerOutput = [] + # Number of KindleGen threads depends on the size of RAM self.pool.setMaxThreadCount(self.threadNumber) for item in outputPath: worker = KindleGenThread(item)