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