mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Send the plugboard cache only once per worker instead of once per job
This commit is contained in:
parent
7a66bbbd40
commit
e50915bfe8
@ -88,7 +88,6 @@ class Saver(QObject):
|
|||||||
self.do_one_signal.connect(self.tick, type=Qt.QueuedConnection)
|
self.do_one_signal.connect(self.tick, type=Qt.QueuedConnection)
|
||||||
self.do_one = self.do_one_collect
|
self.do_one = self.do_one_collect
|
||||||
self.ids_to_collect = iter(self.all_book_ids)
|
self.ids_to_collect = iter(self.all_book_ids)
|
||||||
self.plugboards_cache = {}
|
|
||||||
self.tdir = PersistentTemporaryDirectory('_save_to_disk')
|
self.tdir = PersistentTemporaryDirectory('_save_to_disk')
|
||||||
self.pool = None
|
self.pool = None
|
||||||
|
|
||||||
@ -113,7 +112,7 @@ class Saver(QObject):
|
|||||||
setattr(p, 'no_gc_%s' % id(self), None)
|
setattr(p, 'no_gc_%s' % id(self), None)
|
||||||
if self.pool is not None:
|
if self.pool is not None:
|
||||||
self.pool.shutdown()
|
self.pool.shutdown()
|
||||||
self.jobs = self.pool = self.plugboards_cache = self.plugboards = self.template_functions = self.collected_data = self.all_book_ids = self.pd = self.db = None # noqa
|
self.jobs = self.pool = self.plugboards = self.template_functions = self.collected_data = self.all_book_ids = self.pd = self.db = None # noqa
|
||||||
|
|
||||||
def book_id_data(self, book_id):
|
def book_id_data(self, book_id):
|
||||||
ans = self._book_id_data.get(book_id)
|
ans = self._book_id_data.get(book_id)
|
||||||
@ -153,8 +152,15 @@ class Saver(QObject):
|
|||||||
self.pd.value = 0
|
self.pd.value = 0
|
||||||
if self.opts.update_metadata:
|
if self.opts.update_metadata:
|
||||||
all_fmts = {fmt for data in self.collected_data.itervalues() for fmt in data[2]}
|
all_fmts = {fmt for data in self.collected_data.itervalues() for fmt in data[2]}
|
||||||
self.plugboards_cache = {fmt:find_plugboard(plugboard_save_to_disk_value, fmt, self.plugboards) for fmt in all_fmts}
|
plugboards_cache = {fmt:find_plugboard(plugboard_save_to_disk_value, fmt, self.plugboards) for fmt in all_fmts}
|
||||||
self.pool = Pool(name='SaveToDisk') if self.pool is None else self.pool
|
self.pool = Pool(name='SaveToDisk') if self.pool is None else self.pool
|
||||||
|
try:
|
||||||
|
self.pool.set_common_data(plugboards_cache)
|
||||||
|
except Failure as err:
|
||||||
|
error_dialog(self.pd, _('Critical failure'), _(
|
||||||
|
'Could not save books to disk, click "Show details" for more information'),
|
||||||
|
det_msg=unicode(err.failure_message) + '\n' + unicode(err.details), show=True)
|
||||||
|
self.pd.canceled = True
|
||||||
self.do_one_signal.emit()
|
self.do_one_signal.emit()
|
||||||
|
|
||||||
def do_one_write(self):
|
def do_one_write(self):
|
||||||
@ -260,11 +266,11 @@ class Saver(QObject):
|
|||||||
if self.opts.update_metadata:
|
if self.opts.update_metadata:
|
||||||
if d['fmts']:
|
if d['fmts']:
|
||||||
try:
|
try:
|
||||||
self.pool(book_id, 'calibre.library.save_to_disk', 'update_serialized_metadata', d, self.plugboards_cache)
|
self.pool(book_id, 'calibre.library.save_to_disk', 'update_serialized_metadata', d)
|
||||||
except Failure as err:
|
except Failure as err:
|
||||||
error_dialog(self.pd, _('Critical failure'), _(
|
error_dialog(self.pd, _('Critical failure'), _(
|
||||||
'Could not save books to disk, click "Show details" for more information'),
|
'Could not save books to disk, click "Show details" for more information'),
|
||||||
det_msg=unicode(err) + '\n' + unicode(err.details), show=True)
|
det_msg=unicode(err.failure_message) + '\n' + unicode(err.details), show=True)
|
||||||
self.pd.canceled = True
|
self.pd.canceled = True
|
||||||
else:
|
else:
|
||||||
self.pd.value += 1
|
self.pd.value += 1
|
||||||
@ -298,7 +304,7 @@ class Saver(QObject):
|
|||||||
except Failure as err:
|
except Failure as err:
|
||||||
error_dialog(self.pd, _('Critical failure'), _(
|
error_dialog(self.pd, _('Critical failure'), _(
|
||||||
'Could not save books to disk, click "Show details" for more information'),
|
'Could not save books to disk, click "Show details" for more information'),
|
||||||
det_msg=unicode(err) + '\n' + unicode(err.details), show=True)
|
det_msg=unicode(err.failure_message) + '\n' + unicode(err.details), show=True)
|
||||||
self.pd.canceled = True
|
self.pd.canceled = True
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass # tasks not completed
|
pass # tasks not completed
|
||||||
|
@ -446,8 +446,9 @@ def read_serialized_metadata(data):
|
|||||||
cdata = f.read()
|
cdata = f.read()
|
||||||
return mi, cdata
|
return mi, cdata
|
||||||
|
|
||||||
def update_serialized_metadata(book, plugboard_cache):
|
def update_serialized_metadata(book, common_data=None):
|
||||||
result = []
|
result = []
|
||||||
|
plugboard_cache = common_data
|
||||||
from calibre.customize.ui import apply_null_metadata
|
from calibre.customize.ui import apply_null_metadata
|
||||||
with apply_null_metadata:
|
with apply_null_metadata:
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class Failure(Exception):
|
|||||||
Exception.__init__(self, tf.message)
|
Exception.__init__(self, tf.message)
|
||||||
self.details = tf.tb
|
self.details = tf.tb
|
||||||
self.job_id = tf.job_id
|
self.job_id = tf.job_id
|
||||||
|
self.failure_message = tf.message
|
||||||
|
|
||||||
class Worker(object):
|
class Worker(object):
|
||||||
|
|
||||||
@ -89,7 +90,8 @@ class Pool(Thread):
|
|||||||
needing to be transmitted every time. You must call this method before
|
needing to be transmitted every time. You must call this method before
|
||||||
queueing any jobs, otherwise the behavior is undefined. You can call it
|
queueing any jobs, otherwise the behavior is undefined. You can call it
|
||||||
after all jobs are done, then it will be used for the new round of
|
after all jobs are done, then it will be used for the new round of
|
||||||
jobs. '''
|
jobs. Can raise the :class:`Failure` exception is data could not be
|
||||||
|
sent to workers.'''
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.common_data = data
|
self.common_data = data
|
||||||
for worker in self.available_workers:
|
for worker in self.available_workers:
|
||||||
@ -99,7 +101,7 @@ class Pool(Thread):
|
|||||||
import traceback
|
import traceback
|
||||||
self.terminal_failure = TerminalFailure('Worker process crashed while sending common data', traceback.format_exc())
|
self.terminal_failure = TerminalFailure('Worker process crashed while sending common data', traceback.format_exc())
|
||||||
self.terminal_error()
|
self.terminal_error()
|
||||||
break
|
raise Failure(self.terminal_failure)
|
||||||
|
|
||||||
def start_worker(self):
|
def start_worker(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user