Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python线程,新线程被卡住_Python_Multithreading_User Interface_Pygtk - Fatal编程技术网

Python线程,新线程被卡住

Python线程,新线程被卡住,python,multithreading,user-interface,pygtk,Python,Multithreading,User Interface,Pygtk,我正在尝试用gui编写python应用程序,但python的线程包有问题 import pygtk pygtk.require('2.0') import gtk import threading import time class gui: def main(self): print "starting gui" gtk.main() class logic: def __call__(self): time.sleep(1)

我正在尝试用gui编写python应用程序,但python的线程包有问题

import pygtk
pygtk.require('2.0')
import gtk
import threading
import time

class gui:
    def main(self):
        print "starting gui"
        gtk.main()

class logic:
    def __call__(self):
        time.sleep(1)
        print "did logic"

if __name__ == "__main__":
    threading.Thread(None, logic()).start()
    gui().main()
产出:

starting gui

这种逻辑永远不会发生。为什么?如何解决此问题?

我处理此问题的时间最长,您可以在这里找到解决方案:


我处理这个问题的时间最长,您可以在这里找到解决方案:


哇,这太复杂了。有谁能推荐另一个gui库,让我不用重新编译就可以使用另一个线程吗?使用线程不需要重新编译GTK。我所知道的所有发行版都使用线程支持编译GTK,包括windows上的GTK安装程序。如果您只从主线程访问GUI(例如,通过向线程发送消息、使用idle\u add等),您甚至不需要
threads\u enter
/
threads\u leave
。哇,这相当复杂。有谁能推荐另一个gui库,让我不用重新编译就可以使用另一个线程吗?使用线程不需要重新编译GTK。我所知道的所有发行版都使用线程支持编译GTK,包括windows上的GTK安装程序。如果您仅从主线程访问GUI(例如,通过向线程发送消息、使用idle\u add等),您甚至不需要
threads\u enter
/
threads\u leave