GUI挂起,直到创建所有线程

时间:2013-09-13 06:43:54

标签: python multithreading qt pyside

我创建了一个GUI Scraper(Qt和Python),它运行多个线程.. GUI似乎挂起,直到生成所有线程..我正在运行带有200-300个线程的刮刀..所有线程都是创建GUI正在响应..有没有办法阻止应用程序在创建线程时没有响应..

我在主线程中创建了一个新的Python线程,然后在下面的代码中调用tempthread,该代码位于QThread类中

def tempthread(self):
        self.tempt = threading.Thread(target=self.spawn)
        self.tempt.daemon=True
        self.tempt.start()

def spawn(self):

        global noofthreads
        for xd in range(0,noofthreads):
            t = threading.Thread(target=self.startscrape)
            t.daemon = True 
    t.start()    
            tarray.append(t)
            t1 = threading.Thread(target=self.waitthreads)
            t1.start()
def waitthreads(self)
        for t in tarray:
            t.join()

        self.message.emit("Program Execution Completed")

1 个答案:

答案 0 :(得分:0)

当你需要很多线程时,最好使用线程池。我发现there is python binding for that,所以你应该试试这个。这是similar topic

可悲的是QtConcurrent没有python绑定。这是一个很好的API,但它使用模板并且记录很糟糕。