本文整理汇总了Python中AnyQt.QtCore.QThread.wait方法的典型用法代码示例。如果您正苦于以下问题:Python QThread.wait方法的具体用法?Python QThread.wait怎么用?Python QThread.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QThread
的用法示例。
在下文中一共展示了QThread.wait方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_task
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import wait [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()
示例2: X11EventPoller
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import wait [as 别名]
class X11EventPoller(QObject):
keyPressed = pyqtSignal(object, object)
def __init__(self):
QObject.__init__(self)
self._display = Display()
self._thread = QThread()
self.moveToThread(self._thread)
self._thread.start()
def start(self):
QTimer.singleShot(0, self.run)
def run(self):
ctx = self._display.record_create_context(0,
[record.CurrentClients],
[{
'core_requests': (0, 0),
'core_replies': (0, 0),
'ext_requests': (0, 0, 0, 0),
'ext_replies': (0, 0, 0, 0),
'delivered_events': (0, 0),
'device_events': (X.KeyPress, X.KeyRelease),
'errors': (0, 0),
'client_started': False,
'client_died': False,
}])
self._display.record_enable_context(ctx, self._record_callback)
self._display.record_free_context(ctx)
def _record_callback(self, reply):
QApplication.processEvents()
if reply.category != record.FromServer:
return
if reply.client_swapped:
# received swapped protocol data, cowardly ignored
return
if not len(reply.data) or reply.data[0] < 2:
# not an event
return
data = reply.data
while len(data):
event, data = rq.EventField(None).parse_binary_value(data, self._display.display, None, None)
self.keyPressed.emit(event, data)
def destroy(self):
# self._thread.terminate()
self._thread.wait()
示例3: VizRankDialog
# 需要导入模块: from AnyQt.QtCore import QThread [as 别名]
# 或者: from AnyQt.QtCore.QThread import wait [as 别名]
#.........这里部分代码省略.........
in the vizrank
Returns:
tuple with Vizrank dialog instance and push button
"""
# Monkey patching could be avoided by mixing-in the class (not
# necessarily a good idea since we can make a mess of multiple
# defined/derived closeEvent and hideEvent methods). Furthermore,
# per-class patching would be better than per-instance, but we don't
# want to mess with meta-classes either.
vizrank = cls(master)
button = gui.button(
widget, master, button_label, callback=vizrank.reshow,
enabled=False)
vizrank.selectionChanged.connect(lambda args: set_attr_callback(*args))
master_close_event = master.closeEvent
master_hide_event = master.hideEvent
master_delete_event = master.onDeleteWidget
def closeEvent(event):
vizrank.close()
master_close_event(event)
def hideEvent(event):
vizrank.hide()
master_hide_event(event)
def deleteEvent():
vizrank.keep_running = False
if vizrank._thread is not None and vizrank._thread.isRunning():
vizrank._thread.quit()
vizrank._thread.wait()
master_delete_event()
master.closeEvent = closeEvent
master.hideEvent = hideEvent
master.onDeleteWidget = deleteEvent
return vizrank, button
def reshow(self):
"""Put the widget on top of all windows
"""
self.show()
self.raise_()
self.activateWindow()
def initialize(self):
"""
Clear and initialize the dialog.
This method must be called by the widget when the data is reset,
e.g. from `set_data` handler.
"""
if self._thread is not None and self._thread.isRunning():
self.keep_running = False
self._thread.quit()
self._thread.wait()
self.keep_running = False
self.scheduled_call = None
self.saved_state = None
self.saved_progress = 0
self.update_timer.stop()
self.progressBarFinished()