Only accept non-user and non-network events while processing books.

This commit is contained in:
Charles Haley 2014-01-16 13:08:28 +01:00
parent 4b88f78bd0
commit 7aa33052ac

View File

@ -9,7 +9,7 @@ from threading import Thread, Event
from PyQt4.Qt import (
QMenu, QAction, QActionGroup, QIcon, SIGNAL, Qt, pyqtSignal, QDialog,
QObject, QVBoxLayout, QDialogButtonBox, QCursor, QCoreApplication,
QApplication)
QApplication, QEventLoop)
from calibre.customize.ui import (available_input_formats, available_output_formats,
device_plugins, disabled_device_plugins)
@ -1790,7 +1790,9 @@ class DeviceMixin(object): # {{{
prints('DeviceJob: set_books_in_library: books to process=', total_book_count)
start_time = time.time()
QApplication.setOverrideCursor(Qt.WaitCursor)
try:
current_book_count = 0;
for booklist in booklists:
for book in booklist:
@ -1799,16 +1801,17 @@ class DeviceMixin(object): # {{{
_('Analyzing books on the device: %d%% finished')%(
int((float(current_book_count)/total_book_count)*100.0)))
# I am assuming that this pseudo multi-threading won't break
# anything. Reasons: UI actions that change the DB will happen
# synchronously with this loop, and the device booklist isn't
# used until this loop finishes. Of course, the UI will stutter
# somewhat, but that is better than locking up. Why every tenth
# book? WAG balancing performance in the loop with the user
# being able to get something done
# I am assuming that this sort-of multi-threading won't break
# anything. Reasons: excluding UI events prevents the user
# from explicitly changing anything, and (in theory) no
# changes are happening because of timers and the like.
# Why every tenth book? WAG balancing performance in the
# loop with preventing App Not Responding errors
if current_book_count % 10 == 0:
QCoreApplication.processEvents()
QCoreApplication.processEvents(flags=
QEventLoop.ExcludeUserInputEvents|
QEventLoop.ExcludeSocketNotifiers)
time.sleep(0.01)
current_book_count += 1;
book.in_library = None
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
@ -1873,10 +1876,15 @@ class DeviceMixin(object): # {{{
self.device_manager.sync_booklists(
FunctionDispatcher(self.metadata_synced), booklists,
plugboards, add_as_step_to_job)
except:
traceback.print_exc()
raise
finally:
QApplication.restoreOverrideCursor()
if DEBUG:
prints('DeviceJob: set_books_in_library finished: time=', time.time() - start_time)
prints('DeviceJob: set_books_in_library finished: time=',
time.time() - start_time)
# The status line is reset when the job finishes
return update_metadata
# }}}