def _handle_disconnect(self): self.con.deleteLater() QCoreApplication.quit()
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()
self.hotkey = Hotkey(self.handle_hotkey) def handle_hotkey(self): self.fire.emit() def stop(self): self.hotkey.stop() def run(self): self.hotkey.start() if __name__ == '__main__': import sys import os logging.basicConfig( filename=os.path.expanduser('~/.lit.server.log'), filemode='w', format='%(asctime)s - %(levelname)s - %(message)s', level=logging.DEBUG ) app = QCoreApplication(sys.argv) set_app_info(app, 'litserver') server = Server() QMetaObject.invokeMethod( server, 'start', Qt.QueuedConnection ) sys.exit(app.exec_())
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()