Reputation: 91
I'm new on the use of threads on Python and please, I need help on this.
I'm using PyQt and when I use a loop, the main window is frozen until the loop finish.
I read about threading on python and it seem a solution but I don't know if use of threading that I wrote on my code it's well.
This is an example of my code.
from Window import *
import sys, threading
class Window(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Window()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.button_download, QtCore.SIGNAL('clicked()'), start)
print("I'm the main thread")
def start():
t1 = threading.Thread(target=process)
t1.start()
t1.join()
def process():
for i in range(0, 1000):
print("I'm the thread:", i)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = Window()
myapp.show()
sys.exit(app.exec_())
Many thanks!!
Upvotes: 2
Views: 187
Reputation: 8992
You are joining the thread right away. If you want it to run on background, then remove the line
t1.join()
Upvotes: 2