Reputation: 5823
I am currently having trouble trying to spawn a thread in python while initiating my qt application. The idea in this code is to spawn a python thread that will loop on a function and then initialize my QT application.
import sys
from PyQt4 import QtGui
from pyui import DirectGui
from engines import KCluster_Engine
from threading import Thread
def main():
app = QtGui.QApplication(sys.argv)
dgui = DirectGui()
engine = KCluster_Engine(4, 5)
dgui.set_engine_ref(engine)
engine.assign_interface(dgui)
thread = Thread(target = engine.start())
thread.start()
sys.exit(app.exec_())
thread.join()
if __name__ == '__main__':
main()
The problem behind this is that I cannot use my Qt GUI. My mac gives me a color wheel indicating that my thread that I spawned is spinning, which its supposed to do, but I cannot use my QtApplication.
My thread is spinning on purpose in a while loop, its only supposed to trigger after certain actions on the GUI have been done, but I can't interact with my GUI as the mac color wheel (spinning beachball of death) is preventing me to do so.
But Imagine a mac color wheel cursor (spinning beachball of death) also, screenshot doesn't capture it.
Upvotes: 0
Views: 533
Reputation: 94961
This is happening because you're doing this:
thread = Thread(target = engine.start())
When you really want this:
thread = Thread(target=engine.start)
You're accidentally calling engine.start() in your main thread, so your program is getting stuck in the infinite loop that runs in that method.
Upvotes: 2