Created
February 3, 2016 13:19
-
-
Save nxsofsys/d80487e7605eb7061d88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5.QtCore import QObject, QThread, pyqtSignal | |
from PyQt5.QtCore import qDebug, QCoreApplication, Qt | |
import time | |
import sys | |
class SomeThread(QObject): | |
signal = pyqtSignal(QObject) | |
def __init__(self): | |
QObject.__init__(self) | |
self.thread = QThread() | |
self.wait = self.thread.wait | |
# | |
# self.signal.connect(self.signalHandler, type = Qt.QueuedConnection) | |
self.moveToThread(self.thread) | |
self.signal.connect(self.signalHandler, type = Qt.QueuedConnection) | |
self.thread.started.connect(self.run) | |
self.thread.start() | |
def signalHandler(self, obj): | |
qDebug("signalHandler obj ref counts: " + str(sys.getrefcount(obj))) | |
def run(self): | |
qDebug("Thread sleeps for 1 sec") | |
time.sleep(1) | |
qDebug("Process events now") | |
QCoreApplication.processEvents() | |
self.thread.exit() | |
app = QCoreApplication([]) | |
th = SomeThread() | |
# obj = QObject() | |
def someFunc(): | |
obj = QObject() | |
qDebug("obj ref counts before emit: " + str(sys.getrefcount(obj))) | |
th.signal.emit(obj) | |
qDebug("obj ref counts after emit: " + str(sys.getrefcount(obj))) | |
someFunc() | |
qDebug("Process main events") | |
QCoreApplication.processEvents() | |
qDebug("Process main events done") | |
th.thread.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment