本文整理汇总了Python中calibre.utils.ipc.pool.Pool类的典型用法代码示例。如果您正苦于以下问题:Python Pool类的具体用法?Python Pool怎么用?Python Pool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Pool类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: monitor_scan
def monitor_scan(self):
self.scan_thread.join(0.05)
if self.scan_thread.is_alive():
self.do_one_signal.emit()
return
if self.scan_error is not None:
error_dialog(self.pd, _('Cannot add books'), _(
'Failed to add any books, click "Show details" for more information.'),
det_msg=self.scan_error, show=True)
self.break_cycles()
return
if not self.file_groups:
error_dialog(self.pd, _('Could not add'), _(
'No ebook files were found in %s') % self.source, show=True)
self.break_cycles()
return
self.pd.max = len(self.file_groups)
self.pd.title = _('Reading metadata and adding to library (%d books)...') % self.pd.max
self.pd.msg = ''
self.pd.value = 0
self.pool = Pool(name='AddBooks') if self.pool is None else self.pool
if self.db is not None:
if self.add_formats_to_existing:
self.find_identical_books_data = self.db.data_for_find_identical_books()
else:
try:
self.pool.set_common_data(self.db.data_for_has_book())
except Failure as err:
error_dialog(self.pd, _('Cannot add books'), _(
'Failed to add any books, click "Show details" for more information.'),
det_msg=unicode(err.failure_message) + '\n' + unicode(err.details), show=True)
self.pd.canceled = True
self.groups_to_add = iter(self.file_groups)
self.do_one = self.do_one_group
self.do_one_signal.emit()
示例2: collection_finished
def collection_finished(self):
self.do_one = self.do_one_write
ensure_unique_components(self.collected_data)
self.ids_to_write = iter(self.collected_data)
self.pd.title = _('Copying files and writing metadata...') if self.opts.update_metadata else _(
'Copying files...')
self.pd.max = len(self.collected_data)
self.pd.value = 0
if self.opts.update_metadata:
all_fmts = {fmt for data in itervalues(self.collected_data) for fmt in data[2]}
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
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_type(err.failure_message) + '\n' + unicode_type(err.details), show=True)
self.pd.canceled = True
self.do_one_signal.emit()
示例3: create_spare_pool
def create_spare_pool(self, *args):
if self._spare_pool is None:
num = min(detect_ncpus(), int(config['worker_limit']/2.0))
self._spare_pool = Pool(max_workers=num, name='GUIPool')
示例4: Main
#.........这里部分代码省略.........
prints(message)
import traceback
traceback.print_exc()
if message:
if not self.device_manager.is_running('Wireless Devices'):
error_dialog(self, _('Problem starting the wireless device'),
_('The wireless device driver had problems starting. '
'It said "%s"')%message, show=True)
self.iactions['Connect Share'].set_smartdevice_action_state()
def start_content_server(self, check_started=True):
from calibre.library.server.main import start_threaded_server
from calibre.library.server import server_config
self.content_server = start_threaded_server(
self.library_view.model().db, server_config().parse())
self.content_server.state_callback = Dispatcher(
self.iactions['Connect Share'].content_server_state_changed)
if check_started:
self.content_server.start_failure_callback = \
Dispatcher(self.content_server_start_failed)
def content_server_start_failed(self, msg):
error_dialog(self, _('Failed to start Content Server'),
_('Could not start the content server. Error:\n\n%s')%msg,
show=True)
def resizeEvent(self, ev):
MainWindow.resizeEvent(self, ev)
self.search.setMaximumWidth(self.width()-150)
def create_spare_pool(self, *args):
if self._spare_pool is None:
num = min(detect_ncpus(), int(config['worker_limit']/2.0))
self._spare_pool = Pool(max_workers=num, name='GUIPool')
def spare_pool(self):
ans, self._spare_pool = self._spare_pool, None
QTimer.singleShot(1000, self.create_spare_pool)
return ans
def do_proceed(self, func, payload):
if callable(func):
func(payload)
def no_op(self, *args):
pass
def system_tray_icon_activated(self, r=False):
if r in (QSystemTrayIcon.Trigger, QSystemTrayIcon.MiddleClick, False):
if self.isVisible():
if self.isMinimized():
self.showNormal()
else:
self.hide_windows()
else:
self.show_windows()
if self.isMinimized():
self.showNormal()
@property
def is_minimized_to_tray(self):
return getattr(self, '__systray_minimized', False)
def ask_a_yes_no_question(self, title, msg, det_msg='',
show_copy_button=False, ans_when_user_unavailable=True,
skip_dialog_name=None, skipped_value=True):
示例5: Adder
#.........这里部分代码省略.........
unreadable_files.append(path)
if unreadable_files:
if not self.file_groups:
self.scan_error = _('You do not have permission to read the selected file(s).') + '\n'
self.scan_error += '\n'.join(unreadable_files)
else:
a = self.report.append
for f in unreadable_files:
a(_('Could not add %s as you do not have permission to read the file' % f))
a('')
except Exception:
self.scan_error = traceback.format_exc()
def monitor_scan(self):
self.scan_thread.join(0.05)
if self.scan_thread.is_alive():
self.do_one_signal.emit()
return
if self.scan_error is not None:
error_dialog(self.pd, _('Cannot add books'), _(
'Failed to add any books, click "Show details" for more information.'),
det_msg=self.scan_error, show=True)
self.break_cycles()
return
if not self.file_groups:
error_dialog(self.pd, _('Could not add'), _(
'No ebook files were found in %s') % self.source, show=True)
self.break_cycles()
return
self.pd.max = len(self.file_groups)
self.pd.title = _('Reading metadata and adding to library (%d books)...') % self.pd.max
self.pd.msg = ''
self.pd.value = 0
self.pool = Pool(name='AddBooks') if self.pool is None else self.pool
if self.db is not None:
if self.add_formats_to_existing:
self.find_identical_books_data = self.db.data_for_find_identical_books()
else:
try:
self.pool.set_common_data(self.db.data_for_has_book())
except Failure as err:
error_dialog(self.pd, _('Cannot add books'), _(
'Failed to add any books, click "Show details" for more information.'),
det_msg=unicode(err.failure_message) + '\n' + unicode(err.details), show=True)
self.pd.canceled = True
self.groups_to_add = iter(self.file_groups)
self.do_one = self.do_one_group
self.do_one_signal.emit()
# }}}
def do_one_group(self):
try:
group_id = next(self.groups_to_add)
except StopIteration:
self.do_one = self.monitor_pool
self.do_one_signal.emit()
return
try:
self.pool(group_id, 'calibre.ebooks.metadata.worker', 'read_metadata',
self.file_groups[group_id], group_id, self.tdir)
except Failure as err:
error_dialog(self.pd, _('Cannot add books'), _(
'Failed to add any books, 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()
示例6: Saver
class Saver(QObject):
do_one_signal = pyqtSignal()
def __init__(self, book_ids, db, opts, root, parent=None, pool=None):
QObject.__init__(self, parent)
self.db = db.new_api
self.plugboards = self.db.pref('plugboards', {})
self.template_functions = self.db.pref('user_template_functions', [])
load_user_template_functions('', self.template_functions)
self.collected_data = {}
self.errors = defaultdict(list)
self._book_id_data = {}
self.all_book_ids = frozenset(book_ids)
self.pd = ProgressDialog(_('Saving %d books...') % len(self.all_book_ids), _('Collecting metadata...'), min=0, max=0, parent=parent, icon='save.png')
self.do_one_signal.connect(self.tick, type=Qt.QueuedConnection)
self.do_one = self.do_one_collect
self.ids_to_collect = iter(self.all_book_ids)
self.tdir = PersistentTemporaryDirectory('_save_to_disk')
self.pool = pool
self.pd.show()
self.root, self.opts, self.path_length = sanitize_args(root, opts)
self.do_one_signal.emit()
if DEBUG:
self.start_time = time.time()
def tick(self):
if self.pd.canceled:
self.pd.close()
self.pd.deleteLater()
self.break_cycles()
return
self.do_one()
def break_cycles(self):
shutil.rmtree(self.tdir, ignore_errors=True)
if self.pool is not None:
self.pool.shutdown()
self.setParent(None)
self.jobs = self.pool = self.plugboards = self.template_functions = self.collected_data = self.all_book_ids = self.pd = self.db = None # noqa
self.deleteLater()
def book_id_data(self, book_id):
ans = self._book_id_data.get(book_id)
if ans is None:
try:
ans = BookId(self.db.field_for('title', book_id), self.db.field_for('authors', book_id))
except Exception:
ans = BookId((_('Unknown') + ' (%d)' % book_id), (_('Unknown'),))
self._book_id_data[book_id] = ans
return ans
def do_one_collect(self):
try:
book_id = next(self.ids_to_collect)
except StopIteration:
self.collection_finished()
return
try:
self.collect_data(book_id)
except Exception:
self.errors[book_id].append(('critical', traceback.format_exc()))
self.do_one_signal.emit()
def collect_data(self, book_id):
mi = self.db.get_metadata(book_id)
self._book_id_data[book_id] = BookId(mi.title, mi.authors)
components = get_path_components(self.opts, mi, book_id, self.path_length)
self.collected_data[book_id] = (mi, components, {fmt.lower() for fmt in self.db.formats(book_id)})
def collection_finished(self):
self.do_one = self.do_one_write
ensure_unique_components(self.collected_data)
self.ids_to_write = iter(self.collected_data)
self.pd.title = _('Copying files and writing metadata...') if self.opts.update_metadata else _(
'Copying files...')
self.pd.max = len(self.collected_data)
self.pd.value = 0
if self.opts.update_metadata:
all_fmts = {fmt for data in itervalues(self.collected_data) for fmt in data[2]}
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
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_type(err.failure_message) + '\n' + unicode_type(err.details), show=True)
self.pd.canceled = True
self.do_one_signal.emit()
def do_one_write(self):
try:
book_id = next(self.ids_to_write)
except StopIteration:
self.writing_finished()
return
if not self.opts.update_metadata:
self.pd.msg = self.book_id_data(book_id).title
#.........这里部分代码省略.........