本文整理汇总了Python中PySide.QtCore.QThread.wait方法的典型用法代码示例。如果您正苦于以下问题:Python QThread.wait方法的具体用法?Python QThread.wait怎么用?Python QThread.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtCore.QThread
的用法示例。
在下文中一共展示了QThread.wait方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QApplicationRunner
# 需要导入模块: from PySide.QtCore import QThread [as 别名]
# 或者: from PySide.QtCore.QThread import wait [as 别名]
class QApplicationRunner(QObject):
""" Application runner starts application in own thread """
def __init__(self):
QObject.__init__(self)
self._thread = QThread()
self.moveToThread(self._thread)
self._thread.started.connect(self.start)
self._ev = Event()
self._app = None
self._thread.start()
@Slot()
def start(self):
self.app = Application()
self._ev.set()
self.app.exec_()
def exit(self):
self.app.exit() # perform polite disposal of resources
if self._thread.isRunning():
self._thread.wait(1000) # wait 1 sec
self._thread.terminate() # no-way
@property
def app(self):
if not self._ev.isSet():
self._ev.wait()
return self._app
@app.setter
def app(self, app):
self._app = app
示例2: QWebPageRunner
# 需要导入模块: from PySide.QtCore import QThread [as 别名]
# 或者: from PySide.QtCore.QThread import wait [as 别名]
class QWebPageRunner(QObject):
""" Web page runner starts WebPage instances in one separate thread and implements custom event loop. """
#FIXME: consider using QEventLoop instead
def __init__(self, app):
QObject.__init__(self)
self._thread = QThread()
self.moveToThread(self._thread)
self._thread.started.connect(self.start)
self._destroying = Event()
self._destroying.clear()
self._result = None
self._commandQueue = Queue()
self._app = app
self._thread.start()
@Slot()
def start(self):
try:
while not self._destroying.is_set():
self._app.processEvents()
try:
cmd = self._commandQueue.get(timeout=0.1)
args = ()
if isinstance(cmd, tuple):
if not len(cmd):
continue
args = cmd[1:]
cmd = cmd[0]
if isinstance(cmd, NewPage):
args = (self._app,)
if isinstance(cmd, Command):
cmd(*args)
else:
raise ValueError('Unknown command %s(%s).' % (cmd, args))
except Empty:
pass
except Exception as e:
logger.exception(e)
def exit(self):
self._destroying.set()
if self._thread.isRunning():
self._thread.wait(1000) # wait 1 sec
self._thread.terminate() # no-way
def invoke(self, cmd, *args):
if isinstance(cmd, type) and issubclass(cmd, Command):
cmd = cmd()
if not isinstance(cmd, Command):
cmd = Command(cmd)
cmd.event.clear()
self._commandQueue.put((cmd,)+args)
while not cmd.event.is_set():
self._app.processEvents()
cmd.event.wait(0.1)
return cmd.result
示例3: main
# 需要导入模块: from PySide.QtCore import QThread [as 别名]
# 或者: from PySide.QtCore.QThread import wait [as 别名]
def main():
loadtesterplugins()
qt.mainthread = QThread.currentThread() # Store current thread
qt.initialize_view() # Get the view ready
dispatch_thread = QThread() # The QThread to put the dispatcher on
qt.maindispatch = QTDispatcher(qt.mainview) # Set up the dispatcher
qt.qapp.lastWindowClosed.connect(dispatch_thread.quit) # Connect the close signal to the thread quit signal
qt.maindispatch.moveToThread(dispatch_thread) # Move the dispatcher to the new thread
dispatch_thread.start() # Start the thread
qt.mainview.show() # Show the main window
res = qt.qapp.exec_() # Start the event loop, exits when the last window has been closed
dispatch_thread.wait() # Wait for the dispatcher thread to finish
sys.exit(res)
示例4: main
# 需要导入模块: from PySide.QtCore import QThread [as 别名]
# 或者: from PySide.QtCore.QThread import wait [as 别名]
def main(argv = None):
if argv is None:
argv = sys.argv
version = '20130216' # modification date in yyyymmdd format
connmgr = ConnectionManager()
comm = SerialComm(connmgr)
app = QApplication(argv)
appwindow = MainWindow(connmgr, 'Projector Control Panel')
commthread = QThread()
comm.enumerateSerialPorts()
comm.moveToThread(commthread)
commthread.start()
appwindow.show()
appwindow.writeToLog('Software version ' + version + '.')
result = app.exec_()
commthread.quit()
commthread.wait()
return result