Skip to content

Instantly share code, notes, and snippets.

@NathanW2
Created August 17, 2015 11:16
Show Gist options
  • Save NathanW2/f130fa4f39b8f75d10d6 to your computer and use it in GitHub Desktop.
Save NathanW2/f130fa4f39b8f75d10d6 to your computer and use it in GitHub Desktop.
from PyQt4.QtCore import QThread, QObject, pyqtSignal
import time
class Worker(QObject):
done = pyqtSignal()
finalResult = pyqtSignal(int)
def __init__(self, parent=None):
super(Worker, self).__init__(parent)
def do_stuff(self):
l = 0
for i in range(999999999999):
l += i
self.finalResult.emit(l)
self.done.emit()
def cleanup(self):
print "Cleaning up stuff"
pass
def result(value):
print value
thread = QThread()
worker = Worker()
worker.moveToThread(thread)
worker.done.connect(thread.quit)
worker.finalResult.connect(result)
thread.started.connect(worker.do_stuff)
thread.finished.connect(worker.cleanup)
thread.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment