what is the best practice to separate Pygtk and long running thread code

seb sebastien.thur at laposte.net
Fri Sep 22 11:54:40 EDT 2006


Hi Thomas,

I am running WinXP so that casting processes and getting their results
is not so convenient.

I have tested idle add and it does the job : the thread is running
whenever there is no activity on the gui.
I still do not understand how it can be so responsive 'cause the thread
I am using at the moment do not have any time.sleep(ing).

I am afraid I have still to use an intermediate class between the
computing thread and the gui to send data between the two of them but
now about all the computing time is devoided to the thread.

Thanks a lot !!!

Seb.

ps : the only mod that I have done to the gui.py in the init is

 def __init__(self, path='gui.glade',
                 root='window1',
                 domain=app_name, kwargs={}):
        path = os.path.join(glade_dir, path)
        SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
	self.q=Queue.Queue()
	self.action=act.action(self.q)
	gobject.idle_add(self.action.go)
        #gobject.timeout_add (1000,self.action.go)
	gobject.timeout_add (1000,self.process)



Thomas Guettler wrote:
> seb wrote:
>
> > Hi,
> >
> > I am using pygtk for the first times.
> >
> > I am wondering what would be the best "pattern" to interface pygtk with
> > a thread.
> >
> > The thread is collecting informations (over the network for example) or
> > is doing some long calculations.
>
> Hi,
>
> I would use several *processes*. If your scripts runs on Unix/Linux
> you can use select() on the filedescriptors of the processes you created
> with popen. On Windows you need to poll them, but maybe this is
> better than threads, too. With idle_add you can get data from
> the subproceses. It gets called if there are no actions in the
> event-loop.
>
> HTH,
>  Thomas
>
> --
> Thomas Güttler, http://www.thomas-guettler.de/ http://www.tbz-pariv.de/
> E-Mail: guettli (*) thomas-guettler + de
> Spam Catcher: niemand.leermann at thomas-guettler.de




More information about the Python-list mailing list