当前位置: 首页>>代码示例>>Python>>正文


Python QThread.terminate方法代码示例

本文整理汇总了Python中PySide.QtCore.QThread.terminate方法的典型用法代码示例。如果您正苦于以下问题:Python QThread.terminate方法的具体用法?Python QThread.terminate怎么用?Python QThread.terminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtCore.QThread的用法示例。


在下文中一共展示了QThread.terminate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: QApplicationRunner

# 需要导入模块: from PySide.QtCore import QThread [as 别名]
# 或者: from PySide.QtCore.QThread import terminate [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
开发者ID:pborky,项目名称:webkit-scraper,代码行数:33,代码来源:webkit_scraper.py

示例2: QWebPageRunner

# 需要导入模块: from PySide.QtCore import QThread [as 别名]
# 或者: from PySide.QtCore.QThread import terminate [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
开发者ID:pborky,项目名称:webkit-scraper,代码行数:58,代码来源:webkit_scraper.py

示例3: Progress

# 需要导入模块: from PySide.QtCore import QThread [as 别名]
# 或者: from PySide.QtCore.QThread import terminate [as 别名]

#.........这里部分代码省略.........
    --------------------------------------------------------------------------------------------------------------------
    """
    def createCipherProcess(self):
        if self.mode == 'encryption':
            self.cipher_process = Process(target=self.cipher.encrypt, args=(self.percent_done,
                                                                            self.pause_requested,
                                                                            self.paused))
        elif self.mode == 'decryption':
            self.cipher_process = Process(target=self.cipher.decrypt, args=(self.percent_done,
                                                                            self.pause_requested,
                                                                            self.paused))

    """
    --------------------------------------------------------------------------------------------------------------------
    Begin the encryption/decryption process and start the monitoring thread
    --------------------------------------------------------------------------------------------------------------------
    """
    def begin(self):
        self.monitor_progress_thread.start()
        self.cipher_process.start()

    """
    --------------------------------------------------------------------------------------------------------------------
    Update the progress bar with values from the encryption/decryption process
    --------------------------------------------------------------------------------------------------------------------
    """
    def update(self, percent_done):
        self.progress_bar.setValue(percent_done)

    """
    --------------------------------------------------------------------------------------------------------------------
    request the process to pause
    --------------------------------------------------------------------------------------------------------------------
    """
    def requestPause(self):
        self.pause_requested.value = 1

    """
    --------------------------------------------------------------------------------------------------------------------
    show the cancel message
    --------------------------------------------------------------------------------------------------------------------
    """
    def showCancelMessage(self):
        msgBox = QMessageBox()
        msgBox.setText("Are You Sure You Want To Cancel %s" % self.mode)
        msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
        msgBox.setDefaultButton(QMessageBox.Cancel)
        ret = msgBox.exec_()

        if ret == QMessageBox.Ok:
            self.end_process_early.value = 1
        elif ret == QMessageBox.Cancel:
            self.paused.value = 0
            self.pause_requested.value = 0
            self.pause_sig_sent.value = 0
            self.pause_requested.value = 0

    """
    --------------------------------------------------------------------------------------------------------------------
    Complete encryption / decryption when done
    --------------------------------------------------------------------------------------------------------------------
    """
    def complete(self):
        self.cipher = None
        # terminate the update progress thread
        self.monitor_progress_thread.terminate()
        while self.monitor_progress_thread.isRunning():
            time.sleep(0.01)
        # terminate the cipher process
        self.cipher_process.terminate()
        while self.cipher_process.is_alive():
            time.sleep(0.01)
        self.close()
        # create the filepath to send back to the message box
        fp = ''
        if self.mode == 'encryption':
            fp = self.ciphertext_file_path
        elif self.mode == 'decryption':
            fp = self.plaintext_file_path
        # emit Signal
        self.completeProcessSig.emit(fp)

    """
    --------------------------------------------------------------------------------------------------------------------
    Cancel the encryption / decryption before completion
    --------------------------------------------------------------------------------------------------------------------
    """
    def endEarly(self):
        self.cipher = None
        # terminate the update progress thread
        self.monitor_progress_thread.terminate()
        while self.monitor_progress_thread.isRunning():
            time.sleep(0.01)
        # terminate the cipher process
        self.cipher_process.terminate()
        while self.cipher_process.is_alive():
            time.sleep(0.01)
        self.close()
        # emit Signal
        self.endProcessEarlySig.emit()
开发者ID:fraserjohnstone,项目名称:File-Safe-Pure-Python-AES-Implementation,代码行数:104,代码来源:Progress.py


注:本文中的PySide.QtCore.QThread.terminate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。