这个想法是在列表上继续迭代,将其项添加到gtklist商店, 我用:
multiprocess.Process
在单独的流程中添加行gtk.gdk.threads_enter()
,在调用main方法之前和进程之前错误描述是:尽管循环在后台运行良好,但没有行添加到列表库中。
有人可以建议或指出解决方案吗?
这是 init 方法,循环方法(名为list_updater)
'class sample():
def __init__(self , testmode ):
self.builder = gtk.Builder()
self.builder.add_from_file('test.glade')
self.list_store = self.builder .get_object('liststore1')
self.win = self.builder.get_object('window1')
self.win.set_default_size(200 , 400)
self.win.show()
self.list_ = [0,31,2,5,4,61,8,20,10]
gtk.gdk.threads_enter()
tar = self.list_updater
arg = ()
t = Process(target = tar , args = arg )
t.start()
gtk.gdk.threads_leave()
def list_updater(self ):
while True :
for item in self.list_ :
item = [item]
print item
self.list_store.prepend(item)
time.sleep(1)
答案 0 :(得分:1)
以下是我在原始代码中解决此问题的项目:
多线程与多处理不同,我已经转移到线程。
import threading # instead of multiprocessing
gtk.gdk.threads_enter()
tar = self.list_updater
arg = ()
t = threading.Thread(target = tar , args = arg )
t.start()
gtk.gdk.threads_leave()
gtk.gdk.threads_init(),gtk.gdk.thread.enter()在调用主循环之前,gtk.gdk.thread.leave()之后
def main():
gtk.gdk.threads_init()
gtk.gdk.threads_enter()
gtk.main()
gtk.gdk.threads_leave()