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 self.collected_data.itervalues() 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(err.failure_message) + '\n' + unicode(err.details), show=True) self.pd.canceled = True self.do_one_signal.emit()
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=as_unicode(err.failure_message) + '\n' + as_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 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')