[pygtk] seperate thread for database query
Steve McClure
smcclure at racemi.com
Thu Oct 14 20:09:46 WST 2004
On Thu, 2004-10-14 at 07:19, Matthias Teege wrote:
> Moin,
>
> I try to put long running database selections in a seperate thread
> with teh following code. But the new thread doesnt start. The app does
> run in serial order as before. Whar do I missing?
>
> class Mlist(Thread):
> def __init__(self, app):
> Thread.__init__(self)
> self.app = app
> def run(self):
> print "run"
> self.app.treemodel.clear()
> for row in self.app.ds.select(mdt.mdt):
> tools.insert_row(self.app.treemodel, None, [row.mdt,row.sb])
> print "end"
>
> class appgui:
> def __init__(self):
> """
> ......
> self.list_all()
>
> def list_all(self):
> mlist = Mlist(self)
> gtk.threads_enter()
> mlist.run()
> gtk.threads_leave()
> print "leave"
>
> app=appgui()
> gtk.threads_init()
> gtk.mainloop()
>
You are calling threads_init after the appgui.list_all is called.
In my unpleasant thread experiences, threads_enter() and threads_leave()
don't really get you thread like behavior. That is, threads other than
the main will just block while the main thread works. I'm sure I'm
doing something wrong but I have had to resort to restricting only one
thread to making gtk calls while other threads do work.
Finally, I guess by "serial order" you mean that your terminal shows:
run
end
leave
And the gui isn't updated as stuff is fetched from the DB as you expect.
I believe that is because you are doing everything before you call
gtk.mainloop so there is nothing displayed until everything is done. And
mainloop doesn't run possibly because threads_init is being called after
thread_enter?
_______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
--
Steve McClure <smcclure at racemi.com>
More information about the pygtk
mailing list