本文整理汇总了Python中AnyQt.QtCore.QThread.currentThread方法的典型用法代码示例。如果您正苦于以下问题:Python QThread.currentThread方法的具体用法?Python QThread.currentThread怎么用?Python QThread.currentThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QThread
的用法示例。
在下文中一共展示了QThread.currentThread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_methodinvoke
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def test_methodinvoke(self):
executor = ThreadExecutor()
state = [None, None]
class StateSetter(QObject):
@Slot(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
QCoreApplication.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_task
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def test_task(self):
results = []
task = Task(function=QThread.currentThread)
task.resultReady.connect(results.append)
task.start()
self.app.processEvents()
self.assertSequenceEqual(results, [QThread.currentThread()])
results = []
thread = QThread()
thread.start()
task = Task(function=QThread.currentThread)
task.moveToThread(thread)
self.assertIsNot(task.thread(), QThread.currentThread())
self.assertIs(task.thread(), thread)
task.resultReady.connect(results.append, Qt.DirectConnection)
task.start()
f = task.future()
self.assertIsNot(f.result(3), QThread.currentThread())
self.assertIs(f.result(3), results[-1])
示例3: test_task
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def test_task(self):
results = []
task = Task(function=QThread.currentThread)
task.resultReady.connect(results.append)
task.start()
self.app.processEvents()
self.assertSequenceEqual(results, [QThread.currentThread()])
thread = QThread()
thread.start()
try:
task = Task(function=QThread.currentThread)
task.moveToThread(thread)
self.assertIsNot(task.thread(), QThread.currentThread())
self.assertIs(task.thread(), thread)
results = Future()
def record(value):
# record the result value and the calling thread
results.set_result((QThread.currentThread(), value))
task.resultReady.connect(record, Qt.DirectConnection)
task.start()
f = task.future()
emit_thread, thread_ = results.result(3)
self.assertIs(f.result(3), thread)
self.assertIs(emit_thread, thread)
self.assertIs(thread_, thread)
finally:
thread.quit()
thread.wait()
示例4: _task_finished
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def _task_finished(self, f):
"""
Parameters:
----------
f: conncurent.futures.Future
future instance holding the result of learner evaluation
"""
assert self.thread() is QThread.currentThread()
assert self._task is not None
assert self._task.future is f
assert f.done()
self._task = None
if not self.was_canceled:
self.cancel_button.setDisabled(True)
try:
results = f.result()
except Exception as ex:
log = logging.getLogger()
log.exception(__name__, exc_info=True)
self.error("Exception occured during evaluation: {!r}".format(ex))
for key in self.results.keys():
self.results[key] = None
else:
self.update_view(results[1])
self.progressBarFinished(processEvents=False)
示例5: __emitpending
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def __emitpending(self, index, future):
# type: (int, Future) -> None
assert QThread.currentThread() is self.thread()
assert self.__futures[index] is future
assert future.done()
assert self.__countdone < len(self.__futures)
self.__futures[index] = None
self.__countdone += 1
if future.cancelled():
self.cancelledAt.emit(index, future)
self.doneAt.emit(index, future)
elif future.done():
self.finishedAt.emit(index, future)
self.doneAt.emit(index, future)
if future.exception():
self.exceptionReadyAt.emit(index, future.exception())
else:
self.resultReadyAt.emit(index, future.result())
else:
assert False
self.progressChanged.emit(self.__countdone, len(self.__futures))
if self.__countdone == len(self.__futures):
self.doneAll.emit()
示例6: __onRunFinished
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def __onRunFinished(self):
assert QThread.currentThread() is self.thread()
assert self.__state == State.Processing
assert self.__pendingTask is not None
assert self.sender() is self.__pendingTask.watcher
assert self.__pendingTask.future.done()
task = self.__pendingTask
self.__pendingTask = None
try:
data, n_skipped = task.future.result()
except Exception:
sys.excepthook(*sys.exc_info())
state = State.Error
data = None
n_skipped = 0
self.error(traceback.format_exc())
else:
state = State.Done
self.error()
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()
示例7: __commit_complete
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def __commit_complete(self, f):
# complete the commit operation after the required file has been
# downloaded
assert QThread.currentThread() is self.thread()
assert self.__awaiting_state is not None
assert self.__awaiting_state.future is f
if self.isBlocking():
self.progressBarFinished(processEvents=None)
self.setBlocking(False)
self.setStatusMessage("")
self.__awaiting_state = None
try:
path = f.result()
except Exception as ex:
log.exception("Error:")
self.error(format_exception(ex))
path = None
self.__update_cached_state()
if path is not None:
data = Orange.data.Table(path)
else:
data = None
self.Outputs.data.send(data)
示例8: __onRunFinished
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def __onRunFinished(self):
assert QThread.currentThread() is self.thread()
assert self.__state == State.Processing
assert self.__pendingTask is not None
assert self.sender() is self.__pendingTask.watcher
assert self.__pendingTask.future.done()
task = self.__pendingTask
self.__pendingTask = None
try:
corpus, errors = task.future.result()
except Exception:
sys.excepthook(*sys.exc_info())
state = State.Error
corpus = None
errors = []
self.error(traceback.format_exc())
else:
state = State.Done
self.error()
if corpus:
self.n_text_data = len(corpus)
self.n_text_categories = len(corpus.domain.class_var.values)\
if corpus.domain.class_var else 0
self.corpus = corpus
self.n_skipped = len(errors)
if len(errors):
self.Warning.read_error("Some files" if len(errors) > 1 else "One file")
self.__setRuntimeState(state)
self.commit()
示例9: _task_finished
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def _task_finished(self, f):
"""
Parameters
----------
f : Future
The future instance holding the built model
"""
assert self.thread() is QThread.currentThread()
assert self._task is not None
assert self._task.future is f
assert f.done()
self._task.deleteLater()
self._task = None
self.setBlocking(False)
self.progressBarFinished()
try:
self.model = f.result()
except Exception as ex: # pylint: disable=broad-except
# Log the exception with a traceback
log = logging.getLogger()
log.exception(__name__, exc_info=True)
self.model = None
self.show_fitting_failed(ex)
else:
self.model.name = self.learner_name
self.model.instances = self.data
self.model.skl_model.orange_callback = None # remove unpicklable callback
self.Outputs.model.send(self.model)
示例10: run
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def run(self):
"""
Reimplemented from `QRunnable.run`
"""
self.eventLoop = QEventLoop()
self.eventLoop.processEvents()
# Move the task to the current thread so it's events, signals, slots
# are triggered from this thread.
assert self.task.thread() is _TaskDepotThread.instance()
QMetaObject.invokeMethod(
self.task.thread(), "transfer", Qt.BlockingQueuedConnection,
Q_ARG(object, self.task),
Q_ARG(object, QThread.currentThread())
)
self.eventLoop.processEvents()
# Schedule task.run from the event loop.
self.task.start()
# Quit the loop and exit when task finishes or is cancelled.
self.task.finished.connect(self.eventLoop.quit)
self.task.cancelled.connect(self.eventLoop.quit)
self.eventLoop.exec_()
示例11: setBioMartDatasets
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def setBioMartDatasets(self, datasets):
assert(QThread.currentThread() is self.thread())
self.setEnabled(True)
self.datasets = [data for data in datasets if
getattr(data, "visible", "0") != "0"]
self.datasetsCombo.clear()
self.datasetsCombo.addItems([data.displayName for data in self.datasets])
示例12: _handleException
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def _handleException(self, exception):
assert(QThread.currentThread() is self.thread())
print("Task failed with:", exception, file=sys.stderr)
import logging
log = logging.getLogger(__name__)
log.exception("Error:", exc_info=exception)
self.error(0, str(exception))
self.setEnabled(True)
示例13: __onReportProgress
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
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(prettifypath(arg.lastpath))
self.progress_widget.setValue(arg.progress)
self.progress_widget.setValue(100 * arg.progress)
示例14: transfer
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def transfer(self, obj, thread):
"""
Transfer `obj` (:class:`QObject`) instance from this thread to the
target `thread` (a :class:`QThread`).
"""
assert obj.thread() is self
assert QThread.currentThread() is self
obj.moveToThread(thread)
示例15: _stateChanged
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import currentThread [as 别名]
def _stateChanged(self, future, state):
"""
The `future` state has changed (called by :class:`Future`).
"""
ev = StateChangedEvent(state)
if self.thread() is QThread.currentThread():
QCoreApplication.sendEvent(self, ev)
else:
QCoreApplication.postEvent(self, ev)