예제 #1
0
    def run(self):
        time = QTime()
        eventLoop = QEventLoop()

        self.m_bStop = False

        #        log.debug("Запускаем поток")
        #if not self.initThread():
        #return
        while not self.m_bStop:
            self.m_nTactCounter += 1  # Добавить обнуление при переполнении

            time.start()
            eventLoop.processEvents()

            if not self.workThread():
                self.m_bStop = True
                return
            workTime = time.elapsed()
            if 0 <= workTime < self.m_nTact:
                self.msleep(self.m_nTact - workTime)
            else:
                self.msleep(0)

        eventLoop.processEvents()

        self.exitThread()
예제 #2
0
    def run(self):
        time = QTime()
        eventLoop = QEventLoop()

        self.m_bStop = False

#        log.debug("Запускаем поток")
        #if not self.initThread():
            #return
        while not self.m_bStop:
            self.m_nTactCounter += 1 # Добавить обнуление при переполнении

            time.start()
            eventLoop.processEvents()

            if not self.workThread():
                self.m_bStop = True
                return
            workTime = time.elapsed()
            if 0 <= workTime < self.m_nTact:
                self.msleep(self.m_nTact - workTime)
            else:
                self.msleep(0)

        eventLoop.processEvents()

        self.exitThread()
예제 #3
0
    def call_method(self, method, *args, **kwargs):
        """Call a method."""
        callback = kwargs.get('callback')
        if callback is not None:
            super(QtMessageBusConnection,
                  self).call_method(method, *args, **kwargs)
            return
        replies = []
        loop = QEventLoop()

        def _store_reply(message):
            replies.append(message)
            loop.quit()

        kwargs['callback'] = _store_reply
        super(QtMessageBusConnection,
              self).call_method(method, *args, **kwargs)
        mask = QEventLoop.ExcludeUserInputEvents | QEventLoop.WaitForMoreEvents
        while True:
            loop.processEvents(mask)
            if replies:
                break
        reply = replies[0]
        if 'error' in reply:
            raise MessageBusError(reply['error']['code'],
                                  reply['error'].get('data'))
        return reply.get('result')
예제 #4
0
class _RunnableAsyncCall(_RunnableTask):
    def run(self):
        self.eventLoop = QEventLoop()
        self.eventLoop.processEvents()
        QObject.connect(self._call, SIGNAL("finished(QString)"),
                        lambda str: self.eventLoop.quit())
        QMetaObject.invokeMethod(
            self._call, "moveToAndInit", Qt.QueuedConnection,
            Q_ARG("PyQt_PyObject", QThread.currentThread()))
        self.eventLoop.processEvents()
        self.eventLoop.exec_()
class _RunnableAsyncCall(_RunnableTask):
    def run(self):
        self.eventLoop = QEventLoop()
        self.eventLoop.processEvents()
        QObject.connect(self._call, SIGNAL("finished(QString)"),
                        lambda str: self.eventLoop.quit())
        QMetaObject.invokeMethod(self._call, "moveToAndInit",
                                 Qt.QueuedConnection,
                                 Q_ARG("PyQt_PyObject",
                                       QThread.currentThread()))
        self.eventLoop.processEvents()
        self.eventLoop.exec_()
예제 #6
0
파일: qjsonrpc.py 프로젝트: geertj/bluepass
    def call_method(self, method, *args, **kwargs):
        """Call a method."""
        # XXX: limiting the recusion depth needs more thought
        if len(self._method_calls) > 5:
            raise RuntimeError("recursion level too deep")
        message = jsonrpc.create_request(method, args)
        self.send_message(message)
        replies = []

        def method_response(message, client):
            replies.append(message)

        def method_timeout():
            reply = jsonrpc.create_error(message, jsonrpc.SERVER_ERROR, "Method call timed out")
            replies.append(reply)

        timeout = kwargs.pop("timeout", self.timeout)
        if timeout:
            timer = QTimer(self)
            timer.setInterval(timeout * 1000)
            timer.setSingleShot(True)
            timer.timeout.connect(method_timeout)
            timer.start()
        # Run an embedded event loop to process network events until we get a
        # response. We limit the call depth so that we don't run the risk of
        # overflowing the stack.
        self._method_calls[message["id"]] = method_response
        loop = QEventLoop()
        mask = QEventLoop.ExcludeUserInputEvents | QEventLoop.WaitForMoreEvents
        while True:
            loop.processEvents(mask)
            if replies:
                break
        if timeout:
            timer.stop()
        reply = replies[0]
        del self._method_calls[message["id"]]
        if reply.get("error"):
            raise QJsonRpcError(reply["error"])
        self.message = reply
        return reply.get("result")
예제 #7
0
class _RunnableTask(QRunnable):
    """ Wrapper for an AsyncCall
    """
    def __init__(self, call):
        QRunnable.__init__(self)
        self.setAutoDelete(False)
        self._call = call

    def run(self):
        if isinstance(self._call, AsyncCall):
            self.eventLoop = QEventLoop()
            self.eventLoop.processEvents()
            QObject.connect(self._call, SIGNAL("finished(QString)"),
                            lambda str: self.eventLoop.quit())
            QMetaObject.invokeMethod(
                self._call, "moveToAndInit", Qt.QueuedConnection,
                Q_ARG("PyQt_PyObject", QThread.currentThread()))
            self.eventLoop.processEvents()
            self.eventLoop.exec_()
        else:
            self._return = self._call()
예제 #8
0
class _TaskRunnable(QRunnable):
    """
    A QRunnable for running a :class:`Task` by a :class:`ThreadExecuter`.
    """

    def __init__(self, future, task, args, kwargs):
        QRunnable.__init__(self)
        self.future = future
        self.task = task
        self.args = args
        self.kwargs = kwargs
        self.eventLoop = None

    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 isinstance(self.task.thread(), _TaskDepotThread)
        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.
        # TODO: If the task encounters an critical error it might not emit
        # these signals and this Runnable will never complete.
        self.task.finished.connect(self.eventLoop.quit)
        self.task.cancelled.connect(self.eventLoop.quit)
        self.eventLoop.exec_()
예제 #9
0
파일: concurrent.py 프로젝트: wibrt/orange3
class _TaskRunnable(QRunnable):
    """
    A QRunnable for running a :class:`Task` by a :class:`ThreadExecuter`.
    """

    def __init__(self, future, task, args, kwargs):
        QRunnable.__init__(self)
        self.future = future
        self.task = task
        self.args = args
        self.kwargs = kwargs
        self.eventLoop = None

    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_()
class _RunnableTask(QRunnable):
    """ Wrapper for an AsyncCall
    """
    def __init__(self, call):
        QRunnable.__init__(self)
        self.setAutoDelete(False)
        self._call = call

    def run(self):
        if isinstance(self._call, AsyncCall):
            self.eventLoop = QEventLoop()
            self.eventLoop.processEvents()
            QObject.connect(self._call, SIGNAL("finished(QString)"),
                            lambda str: self.eventLoop.quit())
            QMetaObject.invokeMethod(self._call, "moveToAndInit",
                                     Qt.QueuedConnection,
                                     Q_ARG("PyQt_PyObject",
                                           QThread.currentThread()))
            self.eventLoop.processEvents()
            self.eventLoop.exec_()
        else:
            self._return = self._call()
예제 #11
0
 def call_method(self, method, *args, **kwargs):
     """Call a method."""
     callback = kwargs.get('callback')
     if callback is not None:
         super(QtMessageBusConnection, self).call_method(method, *args, **kwargs)
         return
     replies = []
     loop = QEventLoop()
     def _store_reply(message):
         replies.append(message)
         loop.quit()
     kwargs['callback'] = _store_reply
     super(QtMessageBusConnection, self).call_method(method, *args, **kwargs)
     mask = QEventLoop.ExcludeUserInputEvents | QEventLoop.WaitForMoreEvents
     while True:
         loop.processEvents(mask)
         if replies:
             break
     reply = replies[0]
     if 'error' in reply:
         raise MessageBusError(reply['error']['code'],
                               reply['error'].get('data'))
     return reply.get('result')