本文整理汇总了Python中Orange.widgets.utils.concurrent.ThreadExecutor.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadExecutor.shutdown方法的具体用法?Python ThreadExecutor.shutdown怎么用?Python ThreadExecutor.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.widgets.utils.concurrent.ThreadExecutor
的用法示例。
在下文中一共展示了ThreadExecutor.shutdown方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_methodinvoke
# 需要导入模块: from Orange.widgets.utils.concurrent import ThreadExecutor [as 别名]
# 或者: from Orange.widgets.utils.concurrent.ThreadExecutor import shutdown [as 别名]
def test_methodinvoke(self):
executor = ThreadExecutor()
state = [None, None]
class StateSetter(QObject):
@pyqtSlot(object)
def set_state(self, value):
state[0] = value
state[1] = QThread.currentThread()
def func(callback):
callback(QThread.currentThread())
obj = StateSetter()
f1 = executor.submit(func, methodinvoke(obj, "set_state", (object,)))
f1.result()
# So invoked method can be called from the event loop
self.app.processEvents()
self.assertIs(state[1], QThread.currentThread(),
"set_state was called from the wrong thread")
self.assertIsNot(state[0], QThread.currentThread(),
"set_state was invoked in the main thread")
executor.shutdown(wait=True)
示例2: test_executor
# 需要导入模块: from Orange.widgets.utils.concurrent import ThreadExecutor [as 别名]
# 或者: from Orange.widgets.utils.concurrent.ThreadExecutor import shutdown [as 别名]
def test_executor(self):
executor = ThreadExecutor()
f = executor.submit(QThread.currentThread)
self.assertIsNot(f.result(3), QThread.currentThread())
f = executor.submit(lambda: 1 / 0)
with self.assertRaises(ZeroDivisionError):
f.result()
results = []
task = Task(function=QThread.currentThread)
task.resultReady.connect(results.append, Qt.DirectConnection)
f = executor.submit_task(task)
self.assertIsNot(f.result(3), QThread.currentThread())
executor.shutdown()
示例3: OWGeneInfo
# 需要导入模块: from Orange.widgets.utils.concurrent import ThreadExecutor [as 别名]
# 或者: from Orange.widgets.utils.concurrent.ThreadExecutor import shutdown [as 别名]
#.........这里部分代码省略.........
else:
self.send("Data Subset", None)
def rowFiltered(self, row):
searchStrings = self.search_string.lower().split()
row = " ".join(self.cells[row]).lower()
return not all([s in row for s in searchStrings])
def searchUpdate(self):
if not self.data:
return
searchStrings = self.search_string.lower().split()
index = self.treeWidget.model().sourceModel().index
mapFromSource = self.treeWidget.model().mapFromSource
for i, row in enumerate(self.cells):
row = " ".join(row).lower()
self.treeWidget.setRowHidden(
mapFromSource(index(i, 0)).row(),
QModelIndex(),
not all([s in row for s in searchStrings]))
def selectFiltered(self):
if not self.data:
return
itemSelection = QItemSelection()
index = self.treeWidget.model().sourceModel().index
mapFromSource = self.treeWidget.model().mapFromSource
for i, row in enumerate(self.cells):
if not self.rowFiltered(i):
itemSelection.select(mapFromSource(index(i, 0)),
mapFromSource(index(i, 0)))
self.treeWidget.selectionModel().select(
itemSelection,
QItemSelectionModel.Select | QItemSelectionModel.Rows)
def updateDictyExpressLink(self, genes, show=False):
def fix(ddb):
if ddb.startswith("DDB"):
if not ddb.startswith("DDB_G"):
ddb = ddb.replace("DDB", "DDB_G")
return ddb
return None
if show:
genes = [fix(gene) for gene in genes if fix(gene)]
link1 = '<a href="http://dictyexpress.biolab.si/run/index.php?gene=%s">Microarray profile</a>'
link2 = '<a href="http://dictyexpress.biolab.si/run/index.php?gene=%s&db=rnaseq">RNA-Seq profile</a>'
self.linkLabel.setText(link1 + "<br/>" + link2)
show = any(genes)
if show:
self.dictyExpressBox.show()
else:
self.dictyExpressBox.hide()
def onDictyExpressLink(self, link):
if not self.data:
return
selectedIndexes = self.treeWidget.selectedIndexes()
if not len(selectedIndexes):
QMessageBox.information(
self, "No gene ids selected",
"Please select some genes and try again."
)
return
model = self.treeWidget.model()
mapToSource = model.mapToSource
selectedRows = self.treeWidget.selectedIndexes()
selectedRows = [mapToSource(index).row() for index in selectedRows]
model = model.sourceModel()
selectedGeneids = [self.row2geneinfo[row] for row in selectedRows]
selectedIds = [self.geneinfo[i][0] for i in selectedGeneids]
selectedIds = set(selectedIds)
def fix(ddb):
if ddb.startswith("DDB"):
if not ddb.startswith("DDB_G"):
ddb = ddb.replace("DDB", "DDB_G")
return ddb
return None
genes = [fix(gene) for gene in selectedIds if fix(gene)]
url = str(link) % " ".join(genes)
QDesktopServices.openUrl(QUrl(url))
def onAltSourceChange(self):
self.updateInfoItems()
def onDeleteWidget(self):
# try to cancel pending tasks
if self.initfuture:
self.initfuture.cancel()
if self.itemsfuture:
self.itemsfuture.cancel()
self.executor.shutdown(wait=False)
super().onDeleteWidget()
示例4: OWSetEnrichment
# 需要导入模块: from Orange.widgets.utils.concurrent import ThreadExecutor [as 别名]
# 或者: from Orange.widgets.utils.concurrent.ThreadExecutor import shutdown [as 别名]
#.........这里部分代码省略.........
if self.__state & OWSetEnrichment.RunningEnrichment:
return
# TODO: Move filtering to a filter proxy model
# TODO: Re-enable string search
categories = set(", ".join(cat)
for cat, _ in self.selectedCategories())
# filterString = str(self.filterLineEdit.text()).lower()
model = self.annotationsChartView.model()
def ishidden(index):
# Is item at index (row) hidden
item = model.item(index)
item_cat = item.data(Qt.DisplayRole)
return item_cat not in categories
hidemask = [ishidden(i) for i in range(model.rowCount())]
# compute FDR according the selected categories
pvals = [model.item(i, 4).data(Qt.UserRole)
for i, hidden in enumerate(hidemask) if not hidden]
fdrs = utils.stats.FDR(pvals)
# update FDR for the selected collections and apply filtering rules
itemsHidden = []
fdriter = iter(fdrs)
for index, hidden in enumerate(hidemask):
if not hidden:
fdr = next(fdriter)
pval = model.index(index, 4).data(Qt.UserRole)
count = model.index(index, 2).data(Qt.ToolTipRole)
hidden = (self.useMinCountFilter and count < self.minClusterCount) or \
(self.useMaxPValFilter and pval > self.maxPValue) or \
(self.useMaxFDRFilter and fdr > self.maxFDR)
if not hidden:
fdr_item = model.item(index, 5)
fdr_item.setData(fmtpdet(fdr), Qt.ToolTipRole)
fdr_item.setData(fmtp(fdr), Qt.DisplayRole)
fdr_item.setData(fdr, Qt.UserRole)
self.annotationsChartView.setRowHidden(
index, QModelIndex(), hidden)
itemsHidden.append(hidden)
if model.rowCount() and all(itemsHidden):
self.information(0, "All sets were filtered out.")
else:
self.information(0)
self._updatesummary()
@Slot(float)
def _setProgress(self, value):
assert QThread.currentThread() is self.thread()
self.progressBarSet(value, processEvents=None)
@Slot(str)
def _setRunInfo(self, text):
self.setStatusMessage(text)
def commit(self):
if self.data is None or \
self.__state & OWSetEnrichment.RunningEnrichment:
return
model = self.annotationsChartView.model()
rows = self.annotationsChartView.selectionModel().selectedRows(0)
selected = [model.item(index.row(), 0) for index in rows]
mapped = reduce(operator.ior,
(item.enrichment.query_mapped for item in selected),
set())
assert self.state.namematcher.done()
matcher = self.state.namematcher.result()
axis = 1 if self.genesinrows else 0
if axis == 1:
mapped = [attr for attr in self.data.domain.attributes
if matcher.umatch(attr.name) in mapped]
newdomain = Orange.data.Domain(
mapped, self.data.domain.class_vars, self.data.domain.metas)
data = self.data.from_table(newdomain, self.data)
else:
geneattr = self.geneAttrs[self.geneattr]
selected = [i for i, ex in enumerate(self.data)
if matcher.umatch(str(ex[geneattr])) in mapped]
data = self.data[selected]
self.send("Data subset", data)
def onDeleteWidget(self):
if self.state is not None:
self._cancelPending()
self.state = None
self._executor.shutdown(wait=False)
示例5: OWImportImages
# 需要导入模块: from Orange.widgets.utils.concurrent import ThreadExecutor [as 别名]
# 或者: from Orange.widgets.utils.concurrent.ThreadExecutor import shutdown [as 别名]
#.........这里部分代码省略.........
sys.excepthook(*sys.exc_info())
state = State.Error
image_meta = []
self.error(traceback.format_exc())
else:
state = State.Done
self.error()
categories = {}
for imeta in image_meta:
# derive categories from the path relative to the starting dir
dirname = os.path.dirname(imeta.path)
relpath = os.path.relpath(dirname, task.startdir)
categories[dirname] = relpath
self._imageMeta = image_meta
self._imageCategories = categories
self.__setRuntimeState(state)
self.commit()
def cancel(self):
"""
Cancel current pending task (if any).
"""
if self.__state == State.Processing:
assert self.__pendingTask is not None
self.__pendingTask.cancel()
self.__pendingTask = None
self.__setRuntimeState(State.Cancelled)
@Slot(object)
def __onReportProgress(self, arg):
# report on scan progress from a worker thread
# arg must be a namespace(count: int, lastpath: str)
assert QThread.currentThread() is self.thread()
if self.__state == State.Processing:
self.pathlabel.setText(prettyfypath(arg.lastpath))
def commit(self):
"""
Create and commit a Table from the collected image meta data.
"""
if self._imageMeta:
categories = self._imageCategories
if len(categories) > 1:
cat_var = Orange.data.DiscreteVariable(
"category", values=list(sorted(categories.values()))
)
else:
cat_var = None
# Image name (file basename without the extension)
imagename_var = Orange.data.StringVariable("image name")
# Full fs path
image_var = Orange.data.StringVariable("image")
image_var.attributes["type"] = "image"
# file size/width/height
size_var = Orange.data.ContinuousVariable(
"size", number_of_decimals=0)
width_var = Orange.data.ContinuousVariable(
"width", number_of_decimals=0)
height_var = Orange.data.ContinuousVariable(
"height", number_of_decimals=0)
domain = Orange.data.Domain(
[], [cat_var] if cat_var is not None else [],
[imagename_var, image_var, size_var, width_var, height_var]
)
cat_data = []
meta_data = []
for imgmeta in self._imageMeta:
if imgmeta.isvalid:
if cat_var is not None:
category = categories.get(os.path.dirname(imgmeta.path))
cat_data.append([cat_var.to_val(category)])
else:
cat_data.append([])
basename = os.path.basename(imgmeta.path)
imgname, _ = os.path.splitext(basename)
meta_data.append(
[imgname, imgmeta.path, imgmeta.size,
imgmeta.width, imgmeta.height]
)
cat_data = numpy.array(cat_data, dtype=float)
meta_data = numpy.array(meta_data, dtype=object)
table = Orange.data.Table.from_numpy(
domain, numpy.empty((len(cat_data), 0), dtype=float),
cat_data, meta_data
)
else:
table = None
self.send("Data", table)
def onDeleteWidget(self):
self.cancel()
self.__executor.shutdown(wait=True)
示例6: OWImportImages
# 需要导入模块: from Orange.widgets.utils.concurrent import ThreadExecutor [as 别名]
# 或者: from Orange.widgets.utils.concurrent.ThreadExecutor import shutdown [as 别名]
#.........这里部分代码省略.........
if data:
self._n_image_data = len(data)
self._n_image_categories = len(data.domain.class_var.values)\
if data.domain.class_var else 0
else:
self._n_image_data, self._n_image_categories = 0, 0
self.data = data
self._n_skipped = n_skipped
self.__setRuntimeState(state)
self.commit()
def cancel(self):
"""
Cancel current pending task (if any).
"""
if self.__state == State.Processing:
assert self.__pendingTask is not None
self.__pendingTask.cancel()
self.__pendingTask = None
self.__setRuntimeState(State.Cancelled)
@Slot(object)
def __onReportProgress(self, arg):
# report on scan progress from a worker thread
# arg must be a namespace(count: int, lastpath: str)
assert QThread.currentThread() is self.thread()
if self.__state == State.Processing:
self.pathlabel.setText(prettyfypath(arg.lastpath))
def commit(self):
"""
Commit a Table from the collected image meta data.
"""
self.send("Data", self.data)
def onDeleteWidget(self):
self.cancel()
self.__executor.shutdown(wait=True)
self.__invalidated = False
def eventFilter(self, receiver, event):
# re-implemented from QWidget
# intercept and process drag drop events on the recent directory
# selection combo box
def dirpath(event):
# type: (QDropEvent) -> Optional[str]
"""Return the directory from a QDropEvent."""
data = event.mimeData()
urls = data.urls()
if len(urls) == 1:
url = urls[0]
path = url.toLocalFile()
if path.endswith("/"):
path = path[:-1] # remove last /
if os.path.isdir(path):
return path
return None
if receiver is self.recent_cb and \
event.type() in {QEvent.DragEnter, QEvent.DragMove,
QEvent.Drop}:
assert isinstance(event, QDropEvent)
path = dirpath(event)
if path is not None and event.possibleActions() & Qt.LinkAction:
event.setDropAction(Qt.LinkAction)
event.accept()
if event.type() == QEvent.Drop:
self.setCurrentPath(path)
self.start()
else:
event.ignore()
return True
return super().eventFilter(receiver, event)
def _relocate_recent_files(self):
search_paths = self._search_paths()
rec = []
for recent in self.recent_paths:
kwargs = dict(
title=recent.title, sheet=recent.sheet,
file_format=recent.file_format)
resolved = recent.resolve(search_paths)
if resolved is not None:
rec.append(
RecentPath.create(resolved.abspath, search_paths, **kwargs))
else:
rec.append(recent)
# change the list in-place for the case the widgets wraps this list
self.recent_paths[:] = rec
def workflowEnvChanged(self, key, value, oldvalue):
"""
Function called when environment changes (e.g. while saving the scheme)
It make sure that all environment connected values are modified
(e.g. relative file paths are changed)
"""
self.__initRecentItemsModel()