Example #1
0
class Pool(object):
    def __init__(self):
        self.thread = QThread()
        self.thread.start()
        self.local = QObject()
        self.remote = QObject()
        self.remote.moveToThread(self.thread)

    def start(self, job):
        job.setParent(self.local)
        job = Job(job)
        job.moveToThread(self.thread)
        job.setParent(self.remote)
        QMetaObject.invokeMethod(job, 'run', Qt.QueuedConnection)

    def clear(self):
        for job in self.local.children():
            if hasattr(job, 'cancel'):
                job.cancel()
Example #2
0
class Pool(object):

    def __init__(self):
        self.thread = QThread()
        self.thread.start()
        self.local = QObject()
        self.remote = QObject()
        self.remote.moveToThread(self.thread)

    def start(self, job):
        job.setParent(self.local)
        job = Job(job)
        job.moveToThread(self.thread)
        job.setParent(self.remote)
        QMetaObject.invokeMethod(
            job,
            'run',
            Qt.QueuedConnection
        )

    def clear(self):
        for job in self.local.children():
            if hasattr(job, 'cancel'):
                job.cancel()
Example #3
0
 def __init__(self):
     self.thread = QThread()
     self.thread.start()
     self.local = QObject()
     self.remote = QObject()
     self.remote.moveToThread(self.thread)
Example #4
0
 def __init__(self):
     QThread.__init__(self)
     from hotkey import Hotkey
     self.hotkey = Hotkey(self.handle_hotkey)
Example #5
0
def finished():
    print("post thread: %d" % QThread.currentThreadId())
Example #6
0
 def run(self):
     print("job thread: %d" % QThread.currentThreadId())
     self.finished.emit()
Example #7
0
from qt.QtCore import (QThread, QObject, QCoreApplication, QMetaObject, Qt,
                       Slot, Signal, QRunnable, QThreadPool)


class Job(QObject):

    finished = Signal()

    @Slot()
    def run(self):
        print("job thread: %d" % QThread.currentThreadId())
        self.finished.emit()


def finished():
    print("post thread: %d" % QThread.currentThreadId())


if __name__ == '__main__':
    import sys
    app = QCoreApplication(sys.argv)
    print("main thread: %d" % QThread.currentThreadId())
    thread = QThread()
    thread.start()
    job = Job()
    job.finished.connect(finished, Qt.QueuedConnection)
    job.moveToThread(thread)
    QMetaObject.invokeMethod(job, 'run', Qt.QueuedConnection)
    app.exec_()
    thead.wait()
Example #8
0
def finished():
    print("post thread: %d" % QThread.currentThreadId())
Example #9
0
 def run(self):
     print("job thread: %d" % QThread.currentThreadId())
     self.finished.emit()
Example #10
0
    QThreadPool
)


class Job(QObject):

    finished = Signal()

    @Slot()
    def run(self):
        print("job thread: %d" % QThread.currentThreadId())
        self.finished.emit()


def finished():
    print("post thread: %d" % QThread.currentThreadId())


if __name__ == '__main__':
    import sys
    app = QCoreApplication(sys.argv)
    print("main thread: %d" % QThread.currentThreadId())
    thread = QThread()
    thread.start()
    job = Job()
    job.finished.connect(finished, Qt.QueuedConnection)
    job.moveToThread(thread)
    QMetaObject.invokeMethod(job, 'run', Qt.QueuedConnection)
    app.exec_()
    thead.wait()
Example #11
0
 def __init__(self):
     self.thread = QThread()
     self.thread.start()
     self.local = QObject()
     self.remote = QObject()
     self.remote.moveToThread(self.thread)