def __init__(self, qt_is_safe=False): self.qt_is_safe = qt_is_safe self._blacklist = [] self._tasks = [] self._load_queue = LifoQueue() self._instantiate_queue = LifoQueue() self._observers = [] self.type_mapping = {} self.plugin_types = {} self.instantiating = False # A QRunnable-based background Worker self.plugin_loader = threads.QThreadFutureIterator(self._load_plugins) # Remember all modules loaded before any plugins are loaded; don't bother unloading these self._preloaded_modules = set(sys.modules.keys()) # Observe changes to venvs if venvsobservers is not None: venvsobservers.append(self) self.initialize_types() # Check if cammart should be ignored try: args = parse_args(exit_on_fail=False) include_cammart = not args.nocammart self._blacklist = args.blacklist except RuntimeError: include_cammart = False # ...if so, blacklist it if not include_cammart: self._blacklist.extend(["cammart", "venvs"])
def collectPlugins(self, paths=None): """ Walk through the plugins' places and look for plugins. Then for each plugin candidate look for its category, load it and stores it in the appropriate slot of the category_mapping. Overloaded to add callback. """ self.loading = True self.setPluginPlaces(self.plugindirs + (paths or [])) self.locatePlugins() # Prevent loading two plugins with the same name candidatedict = {c[2].name: c[2] for c in self._candidates} candidatesset = candidatedict.values() for plugin in reversed(self._candidates): if plugin[2] not in candidatesset: msg.logMessage(f'Possible duplicate plugin name "{plugin[2].name}" at {plugin[2].path}', level=msg.WARNING) msg.logMessage(f"Possibly shadowed by {candidatedict[plugin[2].name].path}", level=msg.WARNING) self._candidates.remove(plugin) msg.logMessage("Candidates:") for candidate in self._candidates: msg.logMessage(candidate) future = threads.QThreadFutureIterator(self.loadPlugins, callback_slot=self.showLoading, finished_slot=lambda: setattr(self, 'loadcomplete', True)) future.start() self.notify()
def test_threads_iterator(): from qtpy.QtWidgets import QApplication app = QApplication([]) from xicam.core import threads from qtpy.QtCore import QTimer q = QTimer() results = [] def callback(a): results.append(a) def testiterator(): for i in range(3): yield i def check(): assert sum(results) == 3 t = threads.QThreadFutureIterator(testiterator, callback_slot=callback, finished_slot=check) q.singleShot(1000, t.start) q.singleShot(2000, app.quit) app.exec_()
def test_threads_iterator(qtbot): from xicam.core import threads results = [] def callback(a): results.append(a) def testiterator(): for i in range(3): yield i def check(): assert sum(results) == 3 t = threads.QThreadFutureIterator(testiterator, callback_slot=callback, finished_slot=check) t.start() qtbot.waitSignal(t.sigFinished)