Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/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中不使用Gtk.main调用threading.Timer函数_Python_Gtk_Python Multithreading - Fatal编程技术网

为什么python中不使用Gtk.main调用threading.Timer函数

为什么python中不使用Gtk.main调用threading.Timer函数,python,gtk,python-multithreading,Python,Gtk,Python Multithreading,我正在尝试轮询Gtk应用程序中的函数。代码是 from gi.repository import Gtk import sys,threading def destroy(k): print "destroyed" sys.exit() def poll(): print "called it " t=threading.Timer(1,poll) t.start() build=Gtk.Builder() build.add_from_file('test.glade') # it

我正在尝试轮询Gtk应用程序中的函数。代码是

from gi.repository import Gtk
import sys,threading

def destroy(k):
print "destroyed"
sys.exit()

def poll():
print "called it "
t=threading.Timer(1,poll)
t.start()

build=Gtk.Builder()
build.add_from_file('test.glade')    # it just creates a top level window
window=build.get_object("boxy")
build.connect_signals({"destroyit":destroy})
window.show_all()
t=threading.Timer(1,poll)
t.start()
Gtk.main()
未执行轮询功能。。但是如果我删除Gtk.main(),它就可以正常工作。。。那么到底发生了什么。。为什么它在没有main的情况下工作,而不在main的情况下工作……我如何在这个……中执行轮询函数……除了threading.timer还有其他选择吗


编辑:我通过使用GObject.timeout\u add(5000,poll)找到了解决方法,但我仍然想知道,为什么线程.Timer函数不执行

我找到了我问题的答案

GObject.timeout_add(5000,poll)